php – “modules”组件的配置必须包含“class”元素

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – “modules”组件的配置必须包含“class”元素脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在yii2中定义了一个名为`admin’的模块.
我已在web.PHP配置文件注册了此模块.
但是当我尝试访问它时,我面临一个错误.

这是我的web.PHP

<?PHP

$params = require(__DIR__ . '/params.PHP');

$config = [
    'id' => 'basic','basePath' => dirname(__DIR__),'language'=>'fa_ir','bootstrap' => ['LOG'],'components' => [
        'request' => [
            // !!! insert a secret key in the following (if IT is empty) - this is required by cookie validation
            'cookieValidationKey' => 'SiMhyyhP2MZ_Bai321KfDHFk5uleQFa9',],'jdate' => [
            'class' => 'jDate\DateTime'
        ],'cache' => [
            'class' => 'yii\caching\FileCache','user' => [
            'identityClass' => 'app\models\User','enableAutoLogin' => true,'errorHandler' => [
            'errorAction' => 'site/error','modules' => [
            'admin' => [
                'class' => 'app\modules\admin\Module','mailer' => [
            'class' => 'yii\swiftmailer\Mailer',// send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,'transport' => [
                'class' => 'Swift_SmtpTransport','host' => 'smtp.gmail.com','username' => 'pisheVARis@gmail.COM','password' => 'bhtk1368','port' => '587','encryption' => 'tls','log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,'targets' => [
                [
                    'class' => 'yii\log\FileTarget','levels' => ['error','warning'],'urlManager' => [
            'class' => 'yii\web\UrlManager',// Disable index.PHP
            'showScriptName' => false,// Disable r= routes
            'enablePRettyUrl' => true,'rules' => array(
                '<controller:\w+>/<id:\d+>' => '<controller>/view','<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>','<controller:\w+>/<action:\w+>' => '<controller>/<action>',),'db' => require(__DIR__ . '/db.PHP'),'params' => $params,];

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

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

return $config;

这是我的Module类:

<?PHP

namespace app\modules\admin;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\admin\controllers';

    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
}

但是当我尝试访问mysite / admin / default / index时,我面临“modules”组件的配置必须包含“class”元素错误

请在组件外侧定义模块.喜欢
<?PHP

$params = require(__DIR__ . '/params.PHP');

$config = [
    'id' => 'basic','modules' => [
        'admin' => [
            'class' => 'app\modules\admin\Module',];
}

return $config;

脚本宝典总结

以上是脚本宝典为你收集整理的php – “modules”组件的配置必须包含“class”元素全部内容,希望文章能够帮你解决php – “modules”组件的配置必须包含“class”元素所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。