0
我想要什么的Yii 2.不同的行动取决于传递的参数
我想调用不同的动作对此类URL
abc.com/ — Home page
abc.com/<argument-1>/<argument-2> — Search page
我有什么
这里是我的web.php
路由配置和使用索引操作进行搜索。
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
//Home page
'/' => 'site/index',
//Search
'<tag>/<location>' => 'site/search',
],
],
而在abc.com/
我得到一个无限循环。
Index操作
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index', ['ip-info' => Locator::getLocation()]);
}
搜索行动
public function actionSearch(
array $tag = ['any'],
array $location = ['any'],
$display = 'list',
$sort = 'name'
) {
//...
//some actions to fill the variables.
//...
return $this->render('search', [
'data' => $data,
'display-type' => $display,
'sidebar' => $sidebar,
'countries' => $location,
'sort' => $sort,
'title' => $title,
]);
}
你能发布你的搜索动作 – g9m29
什么代码写在索引操作?请检查 –
如果您从abc.com/中删除/ abc.com,只需尝试abc.com并检查视图,即索引是否有任何重定向代码? –