E
E
evilelf2017-08-23 13:05:30
Yii
evilelf, 2017-08-23 13:05:30

How to make my commands in yii2 console?

Hello!
How to make yii2 see all controllers and actions in a module?
Controllers are in commands.

module code:

namespace app\modules\google;
use Yii;
use \yii\base\BootstrapInterface;
/**
 * google module definition class
 */
class GoogleModule extends \yii\base\Module implements \yii\base\BootstrapInterface
{
    /**
     * @inheritdoc
     */
    public $controllerNamespace = 'app\modules\google\controllers';

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
    
    public function bootstrap($app)
    {
        if ($app instanceof \yii\console\Application) {
            $this->controllerNamespace = 'app\modules\google\commands';
        }
    }
}


Registered in config/console.php where bootstrap and where modules, but the console gives an error: Exception 'yii\base\InvalidConfigException' with message 'Missing required parameter "id" when instantiating "app\modules\google\GoogleModule".'
I want it to be like this: when I called ./yii help google, I got all the available controllers and methods
config/console.php

$config = [
    'id' => 'test-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => [
    	'log',
    	'google',
  ],
  'sourceLanguage'=> 'en',
  'language' => 'ru',
    'controllerNamespace' => 'app\commands',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
//		'google' => [
//			'id' => 'google',
//			'class' => 'app\modules\google\GoogleModule',
//		],
//		'urlManager' => [
//			'enablePrettyUrl' => true,
//			'showScriptName' => false,
//			'rules' => [
//				'google/accounts' => 'google/accounts/index',
//			],
//		],
    ],
  'modules' => [
    'google' => [
      'id' => 'google',
      'class' => 'app\modules\google\GoogleModule',
    ]
  ],
    'params' => $params,
    'controllerMap' => [
    	'google_accounts' => [
      'class' => 'app\modules\google\commands\AccountsController',
    ],
    'google_campaigns' => [
      'class' => 'app\modules\google\commands\CampaignsController',
    ],
//        'fixture' => [ // Fixture generation command line.
//            'class' => 'yii\faker\FixtureController',
//        ],
    ],

];

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question