The question refined: I understand the use of 'admin'=>true/false and also in my case 'user'=>true/false and can create links that are appropriate for each scenario, however I am looking for a way to implement this into the routes file. For example there is already this in the routes file:
Router::connec开发者_如何学Ct('/pages/*', array('controller' => 'pages', 'action' => 'display'));
However I also would like any link that is prefixed to do this same redirection, and remove the prefix.. I tried:
Router::connect('*/pages/*', array('controller' => 'pages', 'action' => 'display', 'user'=>false));
Router::connect('/user/pages/*', array('controller' => 'pages', 'action' => 'display', 'user'=>false));
But this doesnt work. Any help? Cheers
----------(original question below)--------
Just a quick one.. I am unsure how to prevent a prefix, for example if I am in domain.com/admin/order or domain.com/user/order which are admin_ and user_ actions in orders controller and the navigation menu contains links to pages displays (controller pages action display, **) when they are clicked on they are automatically prefixed by the current prefix. How can I set in the router file to redirect wildcards prefixes (ie. /pages/)?
edit- What I mean is I want to redirect to a non prefixed url.... because when the user is in a prefix url and clicks on a link which is simply controller=> action=> , it resorts to prefixing the link automatically with the current prefix, either admin or user in this case, when I simply what a non prefixed link. (i.e I would prefer it if cake were to only use prefixes when it is actually specified in the link involved to do so, rather than to carry on using them on every simple html helper controller,action link.)
If u are using $html helper for creating the links then u can use
$html->link('users', array('prefix' => $this->params['prefix'],'controller' => 'users','action' => 'index'))
I'm not a user of cakePHP so this is a bit of a stab in the dark, but in the Zend framework, within the view you can use $this->baseUrl('controller/action');
this will give you the required url.
For example, if I was at www.example.com/admin/moderate/ and I coded a link the the view using:
<a href="users/search">Search for a user</a>
the link would be:
www.example.com/admin/moderate/users/search
if I used :
<a href="<?= $this->baseUrl('users/search'); ?>">Search for user</a>
the output would now be:
www.example.com/users/search.
After a quick google search I think the cakePHP alternative is Router::url(array('controller'=>'users','action'=>'search'), true);
精彩评论