doubeng3412 2016-08-10 22:40
浏览 591
已采纳

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 01: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部