[ BLACK_SWORD @ 30.03.2012. 18:19 ] @
Pozdrav! krenuo sam da pravim mvc pattern al ne znam dal je ovo ispravno sto radim. Napravio sam foldere controllers --about.php models views --about.php libraries --Bootstrap.php --Loader.php --Controller.php index.php ovo mi je index.php Code: <?php error_reporting(E_ALL); $base_path = dirname(realpath(__FILE__)); $base_path = str_replace('\\', '/', $base_path); define('BASE_PATH', $base_path . '/'); require BASE_PATH . 'libraries/Controller.php'; require BASE_PATH . 'libraries/Bootstrap.php'; $application = new Bootstrap(); Bootstrap.php Code: <?php class Bootstrap { function __construct() { $url = isset($_GET['url']) ? $_GET['url'] : null; $url = rtrim($url, '/'); $url = explode('/', $url); if (empty($url[0])) { require BASE_PATH . 'controllers/index.php'; $controller = new Index(); $controller->index(); return false; } $file = BASE_PATH . 'controllers/' . $url[0] . '.php'; if (file_exists($file)) { require $file; } else { exit('Stranica ne postoji'); } $controller = new $url[0](); if (isset($url[2])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}($url[2]); } else { exit('Stranica ne postoji'); } } else { if (isset($url[1])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}(); } else { exit('Stranica ne postoji'); } } else { $controller->index(); } } } } Loader.php Code: <?php class Loader { public function view($file_name, $data = null) { if (is_array($data)) { extract($data); } require BASE_PATH . 'views/' . $file_name . '.php'; } public function model($file_name) { require BASE_PATH . 'models/' . $file_name . '.php'; } } Controller.php Code: <?php class Controller { public $load; function __construct() { $this->load = new Loader(); } } i sad kad ocu npr napravit stranicu u about.php Code: <?php class About extends Controller { function __construct() { parent::__construct(); } public function index() { $data = array('title' => 'About'); $this->load->view('about', $data); } } views/about.php Code: <html> <head> <title><?php echo $title; ?></title> </head> <body> <h1>About</h1> </body> </html> Dali je ovo dobro vako? Dali neko zna kakav dobar tutorijal za mvc? Hvala |