salut a tous
je vous remercie grafikart pour ce tuto
mais j'ai un petit problem
le problem est
Warning: require(/MVC/core/model.php) [function.require]: failed to open stream: No such file or directory in C:\AppServ\www\MVC\index.php on line 6
Fatal error: require() [function.require]: Failed opening required '/MVC/core/model.php' (include_path='.;C:\php5\pear') in C:\AppServ\www\MVC\index.php on line 6
j'ai essaye de trouver une soulution !!
le source
index.php
<?php
define('ROOT',str_replace('index.php','', $_SERVER'SCRIPT_NAME']));
define('WEBROOT',str_replace('index.php','', $_SERVER'SCRIPT_FILENAME']));
require(ROOT.'core/model.php');
require(ROOT.'core/controller.php');
//model.php
$params = explode('/',$_GET'p']);
$controller = $params[0];
$action = (isset($params[1])) ? $params[1] : 'index';
require('controllers/'.$controller.'.php');
$controller = new $controller();
if(method_exists($controller, $action))
{
unset($params[1],$params[0]);
call_user_func_array(array($controller,$action), $params);
// $controller->$action();
}
else
{
echo 'method '.$action.' not exists';
}
?>
class controller
<?php
class Controller
{
protected $vars = array();
protected $layout = false;
public function __construct()
{
if(isset($this->model))
{
foreach($this->model as $v)
{
$this->LoadModel($v);
}
}
}
public function set($array)
{
if(!is_array($array))
{
return false;
}
$this->vars = array_merge($this->vars,$array);
}
public function render($filename)
{
extract($this->vars);
ob_start();
require(ROOT.'/views/'.get_class($this).'/'.$filename.'.php');
$content_for_layout = ob_get_clean();
if($this->layout == false)
{
echo $content_for_layout;
}
else
{
require(ROOT.'/views/layout/'.$this->layout.'.php');
}
}
public function LoadModel($name)
{
require_once(ROOT.'models/'.strtolower($name).'.php');
$this->Sname = new $name();
}
}
?>
ta un probleme avec ta function GetLast pas avec ton index ni ton controller ! regarde plutot par la !
.htaccess source code
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1
j'ai essaye de corigger le problem
le dernier code
le contoller
<?php
class Controller
{
public $vars = array();
public $layout = false;
public function __construct()
{
if(isset($this->model))
{
foreach($this->model as $v)
{
$this->LoadModel($v);
}
}
else
{
return false;
}
}
public function set($array=array())
{
$this->vars = array_merge($this->vars,$array);
}
public function render($filename)
{
extract($this->vars);
ob_start();
require(ROOT.'views/'.get_class($this).'/'.$filename.'.php');
$content_for_layout = ob_get_clean();
if($this->layout == false)
{
echo $content_for_layout;
}
else
{
$require(ROOT.'views/layout/'.$this->layout.'.php');
}
}
public function LoadModel($name)
{
require_once(ROOT.'models/'.strtolower($name).'.php');
$this->Sname = new $name();
}
}
?>
index.php
<?php
(!defined('WEBROOT')) ? define('WEBROOT',str_ireplace('index.php','', $_SERVER'SCRIPT_NAME'])) : '';
(!defined('ROOT')) ? define('ROOT',str_ireplace('index.php','', $_SERVER'SCRIPT_FILENAME'])) : '';
$connect = mysql_connect('localhost','root','root');
if(!$connect)
{
die('<h1>Connect To DataBase Error</h1>');
}
$select = mysql_select_db('MVC',$connect);
if(!$select)
{
die('<h1>Select DataBase Error : DataBase Not Exists</h1>');
}
require(ROOT.'core/model.php');
require(ROOT.'core/controller.php');
$params = explode('/',$_GET'p']);
$controller = $params[0];
$action = (isset($params[1])) ? $params[1] : 'index';
require('controllers/'.$controller.'.php');
$controller = new $controller();
if(method_exists($controller, $action))
{
unset($params[1],$params[0]);
call_user_func_array(array($controller,$action), $params);
// $controller->$action();
}
else
{
echo 'method '.$action.' not exists';
}
?>
le problem
Fatal error: Call to a member function GetLast() on a non-object in C:\AppServ\www\MVC\controllers\tutorials.php on line 8