cakephp remove controller name from url

爷,独闯天下 提交于 2020-01-07 07:36:44

问题


i am working on a cakephp 2.x .. right now i have a function called forgetpassword and resetpassword in my userscontroller .. i am sending an email to a user..

i am sending a url like this ..this code is written in the forgetpassword function

 $url = Router::url( array('controller'=>'users','action'=>'resetpassword'), true   ).'/'.$key.'#'.$hash;

and i receive this url in my inbox like this

https://www.myweb.com/resetpassword/y2273727372jhgdfjjd2434dff#23232323

when i click the url which is on my inbox .. it is giving me an error .. not going to the resetpassword function .. instead if i add the controller name behind the function then it successfully loading the page

e.g

 https://www.myweb.com/users/resetpassword/y2273727372jhgdfjjd2434dff#23232323

but i dont want the controller name behind the function in the url

routes.php

   Router::connect('/resetpassword', array('controller' => 'users', 'action'=>'resetpassword'));

回答1:


Router::connect('/resetpassword', ...)

means, that you are not using anything after it as passed params etc. But you do that, so correct is:

Router::connect('/resetpassword/*', ...)

Also note that

Router::url( array('controller'=>'users','action'=>'resetpassword'), true   ).'/'.$key.'#'.$hash;

is wrong, it should be - as documented:

Router::url(
    array(
        'controller' => 'users', 
        'action' => 'resetpassword',
        $key, // passed param
        '#' => $hash // hash
    ), true);


来源:https://stackoverflow.com/questions/18214271/cakephp-remove-controller-name-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!