doubeng3412 2016-08-11 06:40
浏览 588
已采纳

Yii2:如何将console命令中的命名参数传递给另一个动作?

I'm running the following console command:

yii t/gen 520 34 -someoption --number=1

and since t/gen this is just an alias to the actual action template/generate-preview I need to pass it on, or redirect, to another controller/action. So I do this:

Yii::$app->runAction('template/generate-preview', [ $ID, $count ]);

So the numbers 520 and 34 are passed on but how do I pass on the named parameters someoption and number? They are options in the actual controller and therefore public properties of that controller (like here).

Is it possible pass on those named parameters, that is, set those properties on the controller class?

  • 写回答

1条回答 默认 最新

  • dongyongan9941 2016-08-11 09:49
    关注

    You can use key-value pairs in parameters list:

    Yii::$app->runAction('template/generate-preview', [
        $ID,
        $count,
        'someoption' => true,
        'number' => 1
    ]);
    

    And do not add -- prefixes to parameters names, they will be prepended automatically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集