【问题标题】:How to get param without using "?" from url in cakephp 3.x如何在不使用“?”的情况下获取参数来自 cakephp 3.x 中的 url
【发布时间】:2018-06-28 06:50:19
【问题描述】:

在这个项目中,我必须从 cakephp 3.x 中的 url 获取参数作为项目文档。

但是在doc中给定url很奇怪,就像那样(新参数传递url)

www.example.com/param_name/param_value

我可以在旧方法参数传递 url 中获取参数值,如下所示。

www.example.com?param_name=param_value

但在较新的方法中使用“/”而不是“?”和“=”,我不知道如何获得该参数值。

【问题讨论】:

    标签: php mod-rewrite cakephp parameter-passing cakephp-3.0


    【解决方案1】:

    在你的 routes.php 中

    $routes->connect('/param_name/:param_value',['controller' => 'YourController','action' => 'view'])-> setPass(['param_value']);
    

    在 src/Controller/YourController.php 中

    public function view($param_value)
    {
       echo $param_value;
    }
    

    【讨论】:

    • 在 rout.php 中声明这样的意思是,在 param_value 之前的 url 中是否需要“:”完整列? /param_name/:param_value
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 2021-01-07
    • 2023-04-09
    • 2015-12-27
    • 2022-12-03
    • 2016-03-17
    • 2011-03-15
    相关资源
    最近更新 更多