Yii2 路由配置 问题

'urlManager' => [

        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'suffix' => '.html',
        'rules' => [
            'gallery/<cat_id:\d+>'                   => 'gallery/list',
            'product/<product_id:\d+>'               => 'product/index',
            'limittimebuy/<rule_id:\d+>'             => 'limittimebuy/brand',
            'paycenter/<order_id:\d+>'               => 'paycenter/index',
            'merchant/<act_id:\d+>/<is_preview:\d+>' => 'merchant/index',
            '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',
            'demoes-<controller:\w+>-<action:\w+>'   => 'demoes/<controller>/<action>',
        ],
    ],
    
    
    
    public function actionIndex($act_id=0,$is_preview=0)
    {
    
    }
    
    问题来了 merchant控制器的 index 方法,第二个参数是可选的,如何在配置文件表示呢??
阅读 2.7k
1 个回答

两种方式:

  • 再加一条路由:'merchant/<act_id:d+>' => 'merchant/index',

  • 修改action为:

public function actionIndex($act_id=0)
    {
     $is_preview=isset($_GET['is_preview'])?$_GET['is_preview']:0;
    }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进