我有一个控制台命令来执行消费者时间,并且我需要知道如何在 YII 中的 Web 应用程序操作中调用(执行)它。
class MyCommand extends CConsoleCommand{
public function actionIndex(){
$model = new Product();
$model->title = 'my product';
...
$model->save();
.
.
.
}
}
我想执行这段代码。
尝试这个:
Yii::import('application.commands.*');
$command = new MyCommand("test", "test");
$command->run(null);
值为“test”的 2 个参数必须设置,但不会产生影响,它们在使用控制台时用于 --help 选项。
/**
* Constructor.
* @param string $name name of the command
* @param CConsoleCommandRunner $runner the command runner
*/
public function __construct($name,$runner)
{
$this->_name=$name;
$this->_runner=$runner;
$this->attachBehaviors($this->behaviors());
}
https://github.com/yiisoft/yii/blob/master/framework/console/CConsoleCommand.php#L65
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)