Yii2 UrlManager。如果匹配的路线返回404

时间:2019-02-06 11:45:32

标签: php routing yii2 router yii2-urlmanager

我的配置中有这样的路由

'vakansii/<country_slug>/<city_slug>' => 'vacancies/country-city',
'vakansii/<country_slug>/<category_slug>' => 'vacancies/country-category',

当我点击链接

domain.com/vacansii/ukraine/city 

-一切正常

但是,如果我点击链接

domain.com/vacancii/ukraine/categoryname 

-我有404错误。

解析会根据第一条规则找到匹配项,然后在此停止。如果匹配返回404以继续解析到最后并尝试其他规则,然后再获得最终的404,该怎么办? 有可能吗?

这也是我的控制器动作的一个例子。

//  vakansii/<country_slug>/<city_slug>

public function actionCountryCity($country_slug, $city_slug)
{
    $country = $this->findCountryBySlug($country_slug);
    $city = $this->findCityBySlug($city_slug);

    $query = Vacancies::find()
    ->where(['country_id' => $country->id, 'city_id' => $city->id])
    ->orderBy(['id' => SORT_DESC]);



//  vakansii/<country_slug>/<category_slug>

public function actionCountryCategory($country_slug, $category_clug)
{
    $country = $this->findCountryBySlug($country_slug);
    $category = $this->findCategoryBySlug($category_clug);

    $query = Vacancies::find()
    ->where(['country_id' => $country->id, 'category_id' => $category->id])
    ->orderBy(['id' => SORT_DESC]); 

0 个答案:

没有答案