I have created a console command in console/controllers
with SuggestionController
.
If i run command like php yii suggestions
, its working.
I want to know how to execute console command from web without any extensions of yii2
.
As of Yii2 - 2.0.11.2 advanced app -- this works
First let's make sure controller and namespace correct. In this case frontend app accessing console application import method()
In console\controllers\FhirController
Set the alias to be available in the console\config\main.php [OPTIONAL]
'aliases' => [
'@common' => dirname(__DIR__),
'@frontend' => dirname(dirname(__DIR__)) . '/frontend',
'@backend' => dirname(dirname(__DIR__)) . '/backend',
'@console' => dirname(dirname(__DIR__)) . '/console',
],
Finally from the frontend view, make the call like this: In this case, calling the controller route fhir then method import()
$consoleController = new console\controllers\FhirController('fhir', Yii::$app);
$consoleController->runAction('import');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With