我将查询字符串以参数SearchController::actionDefault
的形式传递给:GET
q
/search/?q=...
但是,我需要定义一个规则,该规则将使用某个值自动初始化此参数或定义另一个参数。
如果我要求mysite.com/showall
,我需要获得相同的内容,如/search/?q=*
这是我尝试过的:
'/showall' => '/search/default/index/?r=*',
我将查询字符串以参数SearchController::actionDefault
的形式传递给:GET
q
/search/?q=...
但是,我需要定义一个规则,该规则将使用某个值自动初始化此参数或定义另一个参数。
如果我要求mysite.com/showall
,我需要获得相同的内容,如/search/?q=*
这是我尝试过的:
'/showall' => '/search/default/index/?r=*',
我解决了这个!
可以在 urlManager 中设置 defaultParams,最后它看起来像在应用程序配置文件中:
... '组件' => 数组( ... 'urlManager' => 数组( ... '规则' => 数组( …… '/show_all' => array('/search/default/index', 'defaultParams' => array('show_all'=>'-') ), …… ), ... ), ... ),
当您收到不同的请求并且需要将其映射到相同的GET
参数时,接受的答案也有效。
例如,我想要所有这些请求:
user/pics
user/photos
user/pictures
实际生成:user/index?content=photos
.
这可能是一种方法:
'<controller:user>/(<content:photos>|pics|pictures)' => array('<controller>/index', 'defaultParams'=>array('content'=>'photos')),