mercredi 29 avril 2015

architecture MVC script

I write social network with MVC architecture it work localhost (wampserver) correctly but when i upload it on real host i get this error in http://example.com/

Warning: require_once(views/index/index.php): failed to 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 my method not work for example when i go http://ift.tt/1HSFeIr must show register form but 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');
    for ($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 the problem and how can i fix it ?

Aucun commentaire:

Enregistrer un commentaire