开发者

Remote controller name from CakePHP URL

开发者 https://www.devze.com 2023-02-23 07:07 出处:网络
I have a problem with the url rewriting. The problem that I am facing is that currently our urls are like this:

I have a problem with the url rewriting.

The problem that I am facing is that currently our urls are like this:

http://www.xyz.com/sc_users/index

I dont want the controller name to be shown in that url.

Is there a way to achieve that??

First of all thank your guys..

Like I have 8 controllers I dont want the controller name to be shown in my url....this is what I want..

To be more p开发者_如何学运维recise no controller name in my url


You can define custom routes in app/config/routes.php. You'll find the all about routes in the CakePHP cookbook under Defining Routes. For example, a custom route can look like this:

Router::connect(
    '/the_url_you_want_to_use/*', array('controller' => 'sc_users', 'action' => 'index')
);


You need to read up about CakePHP routing, look at the examples under 'defining routes'. Update your question with what you would actually like your URLs to look like and we will be able to help you more effectively.


That's simple : there is a file called routes.php in /config directory : You can do url rewriting stuff there like this :

Router::connect('/pages/*', array('controller' => 'cmsPage', 'action' => 'render'));

You can pass more complicated variables to your controller :

Router::connect('/:id-:lang-:profile-:firstName-:lastName-:profile.htm',
    array('controller' => 'profiles','action' => 'view'),
    array('id'=>'[0-9]*', 'lang'=>'fr','firstName'=>'[^-]*','lastNAme'=>'[^-]*','profile' => $util->keywords['profiles'][0]['fr'], 'pass' => array('id', 'lang'),'profile' => $util->keywords2['profiles'][0]['en'])
)

;

As you can see in the last example I have passed 2 parameters to the controller through 'pass' => array('id', 'lang')

0

精彩评论

暂无评论...
验证码 换一张
取 消