私が欲しいものは
そのような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/
私は無限ループを取得します。
インデックスアクション
/**
* 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,
]);
}
問題は状況の組み合わせにありました。AJAXは間違ったルートリクエストを生成していて、最も近いものcatch
がループを提供していました。これが作業ルールの例です。
'urlManager' => [
'baseUrl' => '/',
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => true,
'rules' => [
//Home page
'/' => 'site/index',
//AJAX
'ajax/<action:\w+>' => 'ajax/<action>',
//Search
'<tag:\w+>/<location:\w+>' => 'site/search',
],
],
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加