cakephp从url中删除控制器名称

cakephp从url中删除控制器名称

本文介绍了cakephp从url中删除控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作cakephp 2.x ..现在我有一个函数,在我的用户控制器中的forgetpassword和resetpassword ..我发送电子邮件给用户..



我发送一个url这样..这个代码写在forgetpassword函数

  $ url = :url(array('controller'=>'users','action'=>'resetpassword'),true)。'/'。$ key。'#'。 

我在收件箱中收到此网址,如下所示


$ b b



当我点击我的收件箱中的网址..它给我一个错误..不会去resetpassword函数..而如果我添加控制器名称后面的函数,那么它成功加载页



例如

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

但我不想要URL中的函数后面的控制器名



routes.php

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


解决方案
 :connect('/ resetpassword',...)

意味着,它作为传递的params等。
但是你这样做,正确的是:

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

另请注意

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

错误,应为 - 如记录所示:

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


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'));
解决方案
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);

这篇关于cakephp从url中删除控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 13:57