Justinas
Justinas

Reputation: 43507

Yii2 extend console MessageController

I have some functionality, that I want to add to yii\console\controllers\MessageController::actionExtract().

So normally what I have done - extended yii controller with my own controller and placed it to app\commands directory.

<?php
namespace app\commands;

class MessageController extends \yii\console\controllers\MessageController{ /* .. */ }

For test purposes I added method named actionTest.

When I do > yii command, all I get is

enter image description here

Now I copy-pasted exactly same controller and just renamed it to MsgController. Previous controller left intact.

So now > yii gives me

enter image description here


yii message/test - 'Unknown command message/test'

yii msg/test - 'OK'


My app\config\console.php has 'controllerNamespace' => 'app\commands'

How should I properly extend MessageController and continue use standard yii command (means not changing controller name to have new command)?

Upvotes: 1

Views: 325

Answers (1)

Bizley
Bizley

Reputation: 18021

Extend the controller like you did and in console configuration add:

'controllerMap' => [
    'message' => 'app\commands\MessageController',
],

Upvotes: 2

Related Questions