Hi,
while writing an admin module I came to a wish to create sub-controllers, or sub-actions, or something like that.
I have a module "admin", with a section "rblocks".
It should have sub-section Links and Shop. I need view, add, and delete actions for both Links and Shop.
I want user to visit ?r=admin/rblocks and then browse to ?r=admin/rblocks/links.
I don’t want actions like ?r=admin/rblocks/linkAdd, I prefer ?r=admin/rblocks/links/add and dedicate all links-related actions into a single class.
But I don’t want a links module - it’s too much.
If I just make a folder admin/controllers/rblocks with controller LinksController, I can’t serve index calls, like site.com/admin/rblocks
If I make a controller controllers/RblocksController - I won’t access controllers/rblocks/LinksController, all will be caught by RblocksController class. I can set an Action class for ‘links’, but it can’t distinguish ‘links/add’ and ‘links/delete’.
I don’t want to pass action as a separate get parameter, it’s better be action in the route.
How would I do the structure for the request routing? maybe you’ll suggest an easy way?
I played with it a bit and came to a solution of the virtual paths served by action classes.
My class LinksActions serves as a sub-controller, I can write actions like ?r=admin/rblocks/links/add and serve the index calls, like ?r=admin/rblocks and ?r=admin/rblocks/links.
The major limitation is that the combination of controller/action should not repeat in the URL.
Pity that CWebApplication::createController() does not store the call route to the controller, just the file path.
I can add it of course, like $this->controllerRoute = $route, but site will break on yii update.
Is there an easier solution?