为什么 url 参数在 cakephp 中索引在 'named' 而不是 'pass'?

Why url parameter is indexed at 'named' instead of 'pass' in cakephp?

我的 url 是:http://localhost/intranet/customers/search/1/1A%3A79%3A32%3A97%3AF2/1 我正在打印参数对象如下:

print_r($this->params); 

这将打印以下数组:

[params] => Array
        (
            [plugin] => 
            [controller] => customers
            [action] => search
            [named] => Array
                (
                    [1A] => 79:32:97:F2
                )

            [pass] => Array
                (
                    [0] => 1
                    [1] => 1
                )

        )

但它应该打印:

[params] => Array
        (
            [plugin] => 
            [controller] => customers
            [action] => search
            [named] => Array
                (

                )

            [pass] => Array
                (
                    [0] => 1
                    [1] => 1A:79:32:97:F2
                    [2] => 1
                )
        ) 

但是当我将 url 更改为:http://localhost/intranet/customers/search/1/abc/1

[params] => Array
        (
            [plugin] => 
            [controller] => customers
            [action] => search
            [named] => Array
                (

                )

            [pass] => Array
                (
                    [0] => 1
                    [1] => abc
                    [2] => 1
                )
        ) 

1A:79:32:97:F2 作为 url 中的参数有什么问题?

您需要禁用命名参数解析的贪婪性,默认情况下所有看起来像命名参数的参数都会被解析(即包含 : 分隔符的值)。

在您的路由配置中,使用 Router::connectNamed() 的第二个参数传递更多选项,类似于此,这将仅启用默认的 CakePHP 分页参数:

Router::connectNamed(
    false, // no custom named parameters
    array(
        'default' => true, // default pagination parameters
        'greedy' => false  // no greediness
    )
);

另见