good morning evreyone I have problem when I was watching "Tutoriel PHP - Développer un site : Jour 2, La structure PHP"
from grafikart I tried to do the same in 29:35 min

namespace Body;
class Dispatcher {
    private static $instance;
    public  $request ;

    public  function __construct(){
        $this->request = new Request() ;
        Rooter::parse($this->request->url,$this->request) ;
        $controller = $this->LoadController() ;
        $controller->view() ; }
    public function LoadController(){
        $name =  ucfirst($this->request->controller).'Controller' ;
        require ROOT.DS."Controller".DS.$name.".php" ;
        return new $name() ;
    }
    } 

and I get the "Fatal error: Class 'PagesController' not found in C:\wamp\www\test\Mon_projet\Body\Dispatcher.php on line 24"
so someone can help me

3 réponses


naimo
Auteur
Réponse acceptée

Hi everyone
Solution : I forgot put namepace before declare my class :D

Did you declare your class ?

new Dispatcher;

Hi,

I think, the problem isn't the Dispatcher class but your class PagesController in line 24
Maybe use a "require" for include your class and "use" if the class have a namespace

hope, I help you