Difference between #5 and #7 of
YII2: Create console commands inside a module or extension

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->controllerMap[$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 ```
8 0
6 followers
Viewed: 64 155 times
Version: 2.0
Category: Tutorials
Written by: MetaCrawler
Last updated by: Luis Armando
Created on: Aug 6, 2015
Last updated: 5 years ago
Update Article

Revisions

View all history