yii框架 - 按请求参数实现路由

时间:2015-10-30 20:55:01

标签: yii yii2

有没有办法根据请求参数实现路由?例如,

/v1/articles - action `serve_articles`
/v1/articles?type=list - action `server_filtered_by_list`

1 个答案:

答案 0 :(得分:2)

The simplest way form me is this

you can add to you (eg: index) action the param you need for you purpose

public function actionIndex($type, $param2, $param3)
{
     ... then your code inclus the call for action in controller or
     .... redirect or
     .... render

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);
}