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並檢查視圖,即索引是否有任何重定向代碼? –