简体   繁体   中英

Yii2 Adding new console controller

Why yii2 throw exception, when I try use console controller? Code:

<?php

namespace app\commands;

use yii\console\Controller;
class Hashtag extends Controller
{


    public function actionIndex($search = 'test')
    {
      echo $search;
    }
}

Controller located in: app\\commands\\HashtagController When using terminal: php yii hashtag

Exception 'yii\base\UnknownClassException' with message 'Unable to find 'app\commands\HashtagController' in file: /var/www/html/yiitask/yii2/commands/HashtagController.php. Namespace missing?'

in /var/www/html/yiitask/yii2/vendor/yiisoft/yii2/BaseYii.php:291

Other controller in this folder that was created before, working well.

Your namespace is wrong set the namespace for console controller properly eg: (depend where you have you console controller directory)

  namespace app\console\controllers;

then could be is missing controller

class HashtagController extends Controller
{

instead of

class Hashtag extends Controller
{

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM