简体   繁体   English

在cakephp中将路由参数设为可选

[英]Make route parameter optional in cakephp

I've created the following route in CakePHP: 我在CakePHP中创建了以下路由:

Router::connect(
            '/design-idea-projects/:filtertype--:id',
            array('controller' => 'ourwork', 'action' => 'designideaprojects'),
            array(
                'pass' => array('filtertype', 'id'),
                'id' => '[0-9]+'
            )
        );

In this route I want to make the part /:filtertype--:id optional. 在此路由中,我希望将/:filtertype--:id部分/:filtertype--:id可选。 How to do this? 这个怎么做? I'm not providing anything after /design-idea-projects/ , it is showing missing controller error. /design-idea-projects/ ,我什么也没提供,显示缺少控制器错误。 I'm really not getting any idea. 我真的不知道

Thanks. 谢谢。

You can try this, hope it will work 您可以尝试一下,希望它能起作用

Router::connect(
            '/design-idea-projects/*',
            array('controller' => 'ourwork', 'action' => 'designideaprojects'),
            array(
                'pass' => array('filtertype', '[0-9]+')
            )
        );

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

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