Voici Mon Dispatcher
<?php
class Dispatcher{
var $request;
function __construct(){
$this->request= new Request();
Router::parse($this->request->url,$this->request);
$controller=$this->loadController();
$action = $this->request->action;
if($this->request->prefix){// Si j'ai un prefix
$action= $this->request->prefix.'_'.$action;
}
if(!in_array($action ,array_diff(get_class_methods($controller),get_class_methods('Controller')))){
$this->errors('Le Controller'.$this->request->controller.'n\'a pas de méthode'.$action);
}
call_user_func_array(array($controller,$action),$this->request->params);
$controller->render($action);
}
function errors($message){
$controller = new Controller($this->request);
$Controller->Session = new Session();
$controller->e404($message);
}
function loadController()
{
$name=ucfirst($this->request->controller).'Controller';
$file=ROOT.DS.'controllers'.DS.$name.'.php';
require $file;
$Controller= new $name($this->request);
$Controller->Session = new Session();
$Controller->Form = new Form($Controller);
return $Controller;
}
}
?>
si je tape l'url localhost/site/un controleur qui n'existe pas au lieu de me redire vert la page 404 (controller n’existe pas)
il m'affiche l'erreur
Warning: require(C:\wamp\www\site\controllers\FfController.php) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\jackess\core\Dispatcher.php on line 39
Fatal error: require() [function.require]: Failed opening required 'C:\wamp\www\site\controllers\FfController.php' (include_path='.;C:\php5\pear') in C:\wamp\www\jackess\core\Dispatcher.php on line 39
quelqu'un peux m'aider sur cette affaire
Merci à tous et bonne nuit.
NB :localhost/site/ url racine
il suffit d'ajouter un test sur le controlleur.php dans la méthode loadController
function loadController()
{
$name=ucfirst($this->request->controller).'Controller';
$file=ROOT.DS.'controllers'.DS.$name.'.php';
if(file_exists($file)){
require $file;
$Controller= new $name($this->request);
$Controller->Session = new Session();
$Controller->Form = new Form($Controller);
return $Controller;
}
else{
$this->errors('Erreur 404 Page Introuvable');
}