0

Файл commands/FlagController.php:

    namespace app\commands;

    use yii;
    use yii\console\Controller;
    use yii\base\Component;
    use app\components\flag\AbstractFlagService;
    use app\components\flag\FlagService;

    class FlagController extends Controller
    {
       public function actionCheck()
       {
            $flagService = \Yii::$app->get('flag-service');
            if(Yii::$app->flag->run()) {
                echo true;
            }
       }
    }
}

Конфиг \config\console.php:

     <?php use \yii\console\controllers\MigrateController;

     $config = [
       'id' => 'basic-console',
       'controllerNamespace' => 'app\commands',
       'components' => [
            'flag' => [
                'class' => 'app/components/flag/FlagService',
             ]
          ],
       ];

        if (YII_ENV_DEV) {

        $config['bootstrap'][] = 'gii';
        $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        ];
         }
return $config;

Вылетает ошибка:

Exception 'ReflectionException' with message 'Class app/components/flag/FlagService does not exist'.

Как правильно использовать компоненты в консольных приложениях?

0

1 ответ 1

1

Нужно указывать id класска, а не путь на диске. Лучше всего писать так:

'class' => app\components\flag\FlagService::class,

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.