繁体   English   中英

Cake PHP 重定向,参数在 url

[英]Cake PHP redirect with parameters in url

我有一个我想重定向到的页面,该页面需要 URL 中的参数: http://www.example.com/myController/myAction/param1:val1/param2:val2

我知道有一个 CakePHP redirect function 用于重定向,其工作方式如下:

 $this->redirect(array("controller" => "myController",
                       "action" => "myAction",
                       $data_can_be_passed_here),
                 $status, $exit);

如何使用上面的 function 添加我想要的参数作为 url 的一部分?

我认为可能还有另一个元素可以添加到数组中,以便我可以传递param1:val1param2:val2

任何帮助将不胜感激!

我不知道为什么我无法在CakePHP文档中找到它,但我终于找到了解决方案。 我在这里发布它,以防其他人有同样的问题。 (如果有人知道文档中的位置,请将其发布,谢谢!)

要重定向到网址:

http://www.example.com/myController/myAction/param1:val1/param2:val2

您可以使用:

 $this->redirect(array("controller" => "myController", "action" => "myAction", "param1" => "val1", "param2" => "val2", $data_can_be_passed_here), $status, $exit); 

希望能帮助到你!

如果您需要使用完全获取参数重定向,则传递'?' $url数组参数的索引:

$this->redirect(
    array(
          "controller" => "myController", 
          "action" => "myAction",
          "?" => array(
              "param1" => "val1",
              "param2" => "val2"
          ),
          $data_can_be_passed_here
    ),
    $status,
    $exit
);

它重定向到/myController/muAction/...?param1=val1&param2=val2

至少在CakePHP 1.3中是这样

相反,您也可以使用此格式

<?php

$this->redirect('/controller/action/par1:par1/par2:par2/');


?>

<?php

$this->redirect('/controller/action/id/10/name/hello/');

?>

我通常做这样的事情: $this->redirect(['action' => 'view', $id, 'admins' => true]);

希望它会对你有所帮助。

CakePHP 4.2中, "param" => "val1"似乎不再起作用。

这是你go的样子:

return $this->redirect(['controller'=>'mycontroller','action' => 'myview', 'myparameter']);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM