Yii2~致命错误:Class' yii \ console \ Controller'找不到

时间:2017-08-31 08:15:13

标签: php yii

大家好我试图学习这个名为YII2的新框架,它现在还很顺利。我遇到的问题是这个

致命错误:班级' yii \ console \ Controller'在第10行的C:\ xampp \ htdocs \ YII2_Framework \ commands \ UsersController.php中找不到

我真的不明白,但也许你们这样做?

这是用户控制器代码:

<?php

namespace app\commands;

use yii\console\Controller;
use app\models\Users;
use Yii;

class UsersController extends Controller
{
    public function actionLoadUsers()
    {

        Users::deleteAll();

        $userData = [
            [
                'first_name' => 'Michael',
                'last_name' => 'Rotteveel',
                'gender' => 'M',
                'status' => 'I failed at not being cripple ~ CrippleVineMan 2k17',
                'username' => 'CrippleVineMan',
                'pass' => '735749MB',

            ],
            [
                'first_name' => 'Wolf',
                'last_name' => 'Man',
                'gender' => 'M',
                'status' => 'Growl ~ WolfMan 2K17',
                'username' => 'WolfMan3000',
                'pass' => 'WolfManI$TheBest',

            ],
            [
                'first_name' => 'Jim',
                'last_name' => 'de Vries',
                'gender' => 'M',
                'status' => 'Anarchist, Anti-Fascist, Browser of the /b/ board, anon.',
                'username' => 'TheAnarchoX',
                'pass' => 'Test123',

            ],

        ];

        foreach ($userData as $data) {
            $user = new Users($data);
            $user->hashPassword = true;
            $user->save();
        }
    }
}

结束控制台文件

<?php

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

$config = [
    'id' => 'basic-console',
    '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',
    ];
}

return $config;

我希望你的codegod可以帮助我解决这个问题,因为到目前为止我非常喜欢它!

先谢谢

0 个答案:

没有答案