How can I point url like /admin/xxx/yyy to controller XXX and action admin_YYY (or something alike) for all controllers and actions?
I want to create administrator's backend, so there will be a set of 'admin' actions, like admin_list, admin_show, admin_delete and so on.
xx666xx
(Jerryablan)
April 23, 2009, 1:20pm
2
Your best bet is a RewriteRule in your .htaccess file if possible. Otherwise you will have to create a controller subclass to handle this special action handling.
mod_rewrite is available, but in this case I will lost reversed routing feature, i.e. it would be impossible to create correct routes via createUrl().
xx666xx
(Jerryablan)
April 23, 2009, 1:42pm
4
Not really.
You can add a rewrite that converts /admin/x/y to /admin/x_y.
createUrl should still work.
will
(Phpwindcn)
April 23, 2009, 3:26pm
5
Quote
How can I point url like /admin/xxx/yyy to controller
XXX and action
admin_YYY (or something alike) for all controllers and actions?
I want to create administrator's backend, so there will be a set of 'admin' actions, like admin_list, admin_show, admin_delete and so on.
Why don't you create an 'admin' module, so that you can just use the default routing
Speaking about 'admin' section - I just like to keep code in one place.
Actually I wonder how deeply can I customize the routing in Yii.
For example:
can I remap URLs like /read/id/100 to /read/100 for all controllers? (without creating config rules for each controler).
can I use capturing groups in pattern for using them in route ? (something like ‘rules’=>array(’/(\w+)/(\d+)’=>‘controller{\1}/action{\2}’)
and so on.
xx666xx
(Jerryablan)
April 23, 2009, 3:53pm
7
I've not delved into the patterns yet. I know you can definitely do it with rewrites.
hi
I am looking for the same feature
I'd like to have :
admin/controllerId => admin/controllerId/admin
admin/controllerId/edit => admin/controllerId/update
admin/controllerId/* => admin/controllerId/admin // default for unknown routes for controllerId
for all controllers
I am coming from cakephp where it was easily achieved, my feeling is that in yii you can not have placeholders for controller names or actions in routes
am I wrong ?
and what would be the way to implement this if it is not possible right now ?
thanks
qiang
(Qiang Xue)
April 27, 2009, 11:49am
9
You are right that currently we do not allow using controller and action placeholders.
Unlike CakePHP and other frameworks, URL management in Yii is two-way. That is, you can use it to do routing and also constructing URLs. We will consider adding support to use controller/action placeholders.
thank you for the answer
should I fill an enhancement ticket ?
ok filled a ticket
could not find how to set it as an enhancement though
guess only admins can dot that
also my formulation may not be the best, hope it can be understood or better formulated by a more advanced user
ajaxian
(Dorioajax)
October 23, 2010, 8:57am
13
thomas.mery:
ok filled a ticket
could not find how to set it as an enhancement though
guess only admins can dot that
also my formulation may not be the best, hope it can be understood or better formulated by a more advanced user
Does this enhancement be implemented in 1.1.4
And if not is there a mean to follow the development and knowing whether this ticket is rejected, accepted …
Thanks
mikl
(Mike)
October 25, 2010, 7:59am
14
If you mean the placeholders for controllers/actions: This is already part of Yii for a long time (1.0.9). See here:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#parameterizing-routes
ajaxian
(Dorioajax)
October 25, 2010, 8:16am
15
Perhaps I do not have understand, but I supposed that this ticket solves one my problem :
I can’t do this with urlManager:
my-smart-controller-name/my-action1 => my-ugly-controller-name/my-action2/12 for instance
example:
having this url: http://website.com/smart/action mapped onto http://website.com/ugly/action2/12
it is the 12 (id for instance) that I can’t capture with urlManager
ajaxian
(Dorioajax)
October 25, 2010, 2:10pm
16
Is my question stupid or there is no answer to it?
thanks
mikl
(Mike)
October 26, 2010, 7:58am
17
You only want one single mapping of ‘/smart/action’ to ‘ugly/action2’ with parameter id=12? If so, you can use a complex rule like:
'/smart/action' =>array('ugly/action2','defaultParams'=>array('id'=>12)),
If you need a dynamic mapping you should explain where you store the information that ‘smart/action’ should be translated to id=12.