I was studying a couple PHP frameworks and then decided to build my own, of course. But i'm facing one issue. I have a Router class that handles dynamically the HTTP requests and it basically explodes the URL into elements dividing it by the slash and storing it into an array, then a function is called to check if the first element is a valid Controller. If it is valid, the function should require it, but that's where i'm stuck, because it seems that i can't require a file like:
if (file_exists(CONTROLLERS_DIR . $this->url[0] . '.php')) { require \App\Controllers\$this->url[0] }
How can I require a file like that using namespaces?
Thanks.
if (file_exists(CONTOLLERS_DIR . $this->url[0])) { require CONTOLLERS_DIR . $this->url[0] }?$this->url[0]? Is it correct?$ctrl = '\\App\\Contrllers\\'.$this->url[0]; $c = new $ctrl;oh you gotta escape your slashes too. see here for how i accomplished this: github.com/r3wt/RedBeanFVM/blob/master/RedBeanFVM/…