F
F
fsanday2017-03-20 15:06:05
Yii
fsanday, 2017-03-20 15:06:05

Yii2 console application class not found error?

Good afternoon, tell me, please, what is the problem.
yii2 - basic
console.php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');

$config = [
    'id' => 'basic-console',
  'name' => 'Инвестиционные проекты России - информационный портал',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'app\commands',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
    ],
    'params' => $params,
    /*
    'controllerMap' => [
        'fixture' => [ // Fixture generation command line.
            'class' => 'yii\faker\FixtureController',
        ],
    ],
    */
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

controller:
yii/commands/
<?php
namespace app\commands;

use Yii;
use yii\console\Controller;
use yii\commands\models\Maildelivery;

class MaildeliveryController extends Controller
{
  public $models_delivery;	
 public function actionIndex()
    {
      $this -> models_delivery = new Maildelivery();
      //$this -> time_now = time();
          }
}

model:
commands/models/
namespace app\commands\models;
//namespace yii\helpers;

use Yii;
use yii\base\Model;
use yii\helpers\ArrayHelper;

class Maildelivery extends \yii\db\ActiveRecord
{	
  public $table_name_logs = 'logs_sendmail';

  public static function tableName()
    {
        return 'list';
    }
}

run in console:
php yii maildelivery
PHP Fatal error: Class 'yii\commands\models\Maildelivery' not found in /var/www/html/commands/MaildeliveryController.php on line 141

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-03-20
@fsanday

namespace app\commands\models;this is in the model
use yii\commands\models\Maildelivery;and so you are trying to use in the controller (and you need use app\commands\models\Maildelivery;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question