Changes
Title
unchanged
YII2: Create console commands inside a module or extension
Category
unchanged
Tutorials
Yii version
changed
2.0
Tags
changed
yii2, config,tutorial, configyii2
Content
changed
[...]
**1) Create a new module in your application.** <br>
(I named it "example_commands" for this instructions)
Generate new module from commandline with gii (or use gii-webinterface)
```php
command> yii gii/module --moduleID=example_commands --moduleClass=
"'app\modules\example_commands\Module
"'
Running 'Module Generator'...[...]
app/modules/example_commands/Module.php
```php
namespace app\modules\example_commands;[...]
{
if ($app instanceof \yii\console\Application) {
$app $this->controller
Map[$this->id] = [
'class'Namespace =
> 'app\modules\example_commands\commands
\TestingController',
'module' => $this,
]';
}
}[...]
app/modules/example_commands/commands/TestingController.php
```php
namespace app\modules\example_commands\commands;[...]
app/config/console.php
```php
'bootstrap' => [
// ... other bootstrap components ...[...]
moduleId/controller/action
```php
command>yii example_commands/testing/index
hello world from module
```