php - architecture MVC script -
i write social network mvc architecture work localhost (wampserver) correctly when upload on real host error in http://example.com/
warning: require_once(views/index/index.php): failed open stream: no such file or directory in /home3/farazenc/public_html/fb/views/index.php on line 14 fatal error: require_once(): failed opening required 'views/index/index.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home3/farazenc/public_html/fb/views/index.php on line 14
and method not work example when go http://example.com/index/register must show register form show 404
my main file: .htaccess
rewriteengine on rewritecond %{request_filename} -s [or] rewritecond %{request_filename} -l [or] rewritecond %{request_filename} -d rewriterule ^.*$ - [nc,l] rewriterule ^(.+)$ index.php?url=$1 [qsa,l]
index.php
<?php session_start(); require_once './config.php'; require_once './lib/database.php'; require_once ('./lib/function.php'); $connect = database::connect(); function __autoload($classname) { $directrey = array('controllers', 'models'); ($i = 0; $i < sizeof($directrey); $i++) { if (file_exists($directrey[$i] . '/' . $classname . '.php')) { require_once ($directrey[$i] . '/' . $classname . '.php'); } } } if (isset($_get['url'])) { $url = $_get['url']; $split = preg_split('/[\/\\\]/', $url); if (sizeof($split) == 1) { if (!file_exists('controllers/' . $split[0] . 'controller.php')) { require_once ('./controllers/checkpage.php'); checkpagecontroller::check($split[0]); } else { $classname = $split[0] . 'controller'; $controller = new $classname(); } } elseif (sizeof($split) == 2) { if (file_exists('controllers/' . $split[0] . 'controller.php')) { if (empty($split[1])) { $classname = $split[0] . 'controller'; $controller = new $classname(); } else { $classname = $split[0] . 'controller'; $controller = new $classname(); if (method_exists($controller, $split[1])) { $controller->$split[1](); } else { require_once ('./views/404.php'); } } } else { require_once ('./views/404.php'); } } } else { require_once ('./controllers/indexcontroller.php'); $indexcontroller = new indexcontroller(); } if (isset($_post['action'])) { $ajax = new ajax(); $ajax->$_post['action'](); }
controller.php
<?php abstract class controller { public function render($file) { if (!isset($_post['action'])) { global $split; $d = empty($split) ? 'index' : $split[0]; $content = "views/$d/$file.php"; require_once ('views/index.php'); } } public function user_views($file){ if (isset($_session['user'])){ require_once ('views/user/'.$file.'.php'); } else { require_once ('views/index.php'); } } public function admin_views($file){ if (isset($_session['admin'])){ global $split; $d = empty($split) ? 'index' : $split[0]; $content = "views/$d/$file.php"; require_once ("views/admin/admin.php"); } else { require_once ('views/admin/login.php'); } } }
indexcontroller.php
class indexcontroller extends controller { public function __construct() { global $split; if (empty($split[1])) { $this->render('index'); } } public function register() { $this->render('register'); } }
views/index.php:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>social network</title> <link href="<?php echo url ?>/css/style.css" rel="stylesheet"> <script type="text/javascript" src="<?php echo url ?>/js/ajax.js"></script> <script type="text/javascript" src="<?php echo url ?>/js/jquery.js"></script> </head> <body> <div style="width:1000px;height:650px;margin:50px auto;"> <div id="content"> <?php require_once($content); ?> </div> <div id="ads" style="margin-right:15px;"> <img src="<?php echo url ?>/images/ads-120.jpg"> <img src="<?php echo url ?>/images/ads-120.jpg"> </div> </div> </body> </html>
what's problem , how can fix ?
i had similar problem in past. if file permission correct (755/644), advice check selinux (for rhel/centos etc.). selinux default configured permit httpd work files in /var/www/html directory not outside directory.
if such software working (try "sestatus" command), can disable opening selinux config file (usually /etc/selinux/config) , change line:
selinux=enforcing
to:
selinux=disabled
and reboot system.
afted "sestatus" command must show that:
selinux status: disabled
and test code again (but make sure activate selinux after tests). if helps, need config accordingly using command:
$ chcon -r --type=httpd_sys_content_t /path_to_document_root_of_you_great_site
or more permanent solution (better way):
$ semanage fcontext -a -t httpd_sys_content_t '/path_to_document_root_of_you_great_site(/.*)?' $ restorecon -r -v /path_to_document_root_of_you_great_site
if need httpd can change files use "httpd_sys_rw_content_t" instead of "httpd_sys_content_t"
p.s. i'm apologize english
reference:
Comments
Post a Comment