How to call a console command in web application action in Yii?
console-application, yii
Solution
try this:
Yii::import('application.commands.*');
$command = new MyCommand("test", "test");
$command->run(null);
The 2 parameters with value "test" must be set but do not have an impact, they are used for the --help option when using the console.
/**
* 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
Problem
I have a console command to do a consumer time, AND I need to know how to call (execute) it in a web application action in YII. ``` class MyCommand extends CConsoleCommand{ public function actionIndex(){ $model = new Product(); $model->title = 'my product'; ... $model->save(); . . . } } ``` I want to execute this code.