I am currently working on a private project and while at it, giving ezvMvcTools a shot. I’m a big fan of ezComponents and using ezcMail and ezcGraph on a regular basis. So far, ezcMvcTools looks like an interesting MVC implementation with some differences to the typical ones I’ve used by now.
While adapting the hello world application to my needs I ran into some trouble: Since I am pretty lazy and used to comfortable routing from my other MVC symfony, I didn’t want to set every single route manually. So I found ezcMvcCatchallRoute which maps URLs of “/<controller>/<action>” automatically, just what I wanted. Only problem was, the url-part “<controller>” was translated to the classname “<controller>Controller” and had no option to add some prefix to this.
There was a prefix-option, but this was meant for route-prefixing ( e.g. if you wanted the route to match all routes that look like “/seo<Controller>/<action>”).
But it was quite easy to extend the function to fit my needs, so every controller classname would be prefixed with my project’s class-prefix:
class portfolioCatchAllRoute extends ezcMvcCatchAllRoute { /** * * @var string */ protected $controllerNamePrefix; /** * * @return string */ public function getControllerNamePrefix() { return $this->controllerNamePrefix; } /** * * @param string $controllerNamePrefix */ public function setControllerNamePrefix($controllerNamePrefix) { $this->controllerNamePrefix = $controllerNamePrefix; } /** * * overload ezcMvcCatchAllRoute::createControlllerName() to make use of controllerNamePrefix * * @return string */ public function createControllerName() { $controllerName = $this->getControllerNamePrefix() . ucfirst( parent::createControllerName() ); return $controllerName; } }
usage in your router:
class portfolioRouter extends ezcMvcRouter { public function createRoutes() { $catchallRoute = new portfolioCatchAllRoute('index', 'index'); $catchallRoute->setControllerNamePrefix( 'portfolio' ); return array( $catchallRoute ); } }
