I would like to create a generic module/controller/action route in Zend Framework 2 to be used with ZF2 MVC architecture.
In ZF1 the default route was defined like /[:module][/:controller][/:action]
where module would default to default
, controller would default to index
and action to index
.
Now, ZF2 changed the way modules are intended, from simple groups of controllers and views, to real standalone applications, with explicit mapping of controller name to controller class.
Since all controller names must be unique across all modules, I was thinking to name them like modulename-controllername
but I would like the URL to look like /modulename/controllername
without the need to create specific routes for each module, using something like the old default route for ZF1 described above.
If you use the Zend Skeleton Application you have already configured this default controller.
See here https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php
To have a general/standard routing system for a zf2 module, this is my solution for just one controller "module\controller\index" ( default controller ) :
then in our controller "profil\Controller\Index" we have three actions "index" "home" "signout" :
and thank you anyway :)
Yes it is very possible, but you will have to do a little work. Use the following config:
Then you have to write your own
My\Route\Matcher
to create a Routemap object that the MVC can use. It's not hard, look at the other route matchers already in the framework and you'll get the idea.