9three Posted April 14, 2010 Report Share Posted April 14, 2010 Hey, Instead of using a switch statement like on the Advanced PHP video, I'm doing this: public function route() { $controllerClass = 'application/controllers/' .$this->getController(). 'Controller.php'; $className = $this->getController().'Controller'; if (file_exists($controllerClass)) return new $className($this->getController(), $this->getAction()); else return new errorController($this->getController(), $this->getAction()); } As you can see, the $className stores the actual class name. The problem is that I can't use namespaces when I do this. Controller\$className(); -- returns a syntax error. Not sure if this is something that still needs to get fixed as I know namespaces are still new to PHP. Or does someone know a workaround? Quote Link to comment Share on other sites More sharing options...
grezman Posted July 7, 2010 Report Share Posted July 7, 2010 I run into the same problem. Try using the full namespace as a class name. Do not use an alias because it will not work. Use the full call. i.e. $classname = 'application\controllers\\'.$this->getController().'Controller' ; return new $classname($this->getController(), $this->getAction()); It worked for me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.