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.

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

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题