Yii Boilerplate和用户管理模块

时间:2013-06-24 14:45:57

标签: yii yii-extensions

任何人都可以帮助并建议如何将yii用户管理模块安装到yii样板中吗?

我下载了auth模块并放在common / modules文件夹中,然后编辑backend / config / main.php,如下所示:

$backendConfigDir = dirname(__FILE__);
$root = $backendConfigDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';

$params = require_once($backendConfigDir . DIRECTORY_SEPARATOR . 'params.php');

// Setup some default path aliases. These alias may vary from projects.
Yii::setPathOfAlias('root', $root);
Yii::setPathOfAlias('common', $root . DIRECTORY_SEPARATOR . 'common');
Yii::setPathOfAlias('backend', $root . DIRECTORY_SEPARATOR . 'backend');
Yii::setPathOfAlias('www', $root . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'www');
/* uncomment if you need to use frontend folders */
/* Yii::setPathOfAlias('frontend', $root . DIRECTORY_SEPARATOR . 'frontend'); */


$mainLocalFile = $backendConfigDir . DIRECTORY_SEPARATOR . 'main-local.php';
$mainLocalConfiguration = file_exists($mainLocalFile) ? require($mainLocalFile) : array();

$mainEnvFile = $backendConfigDir . DIRECTORY_SEPARATOR . 'main-env.php';
$mainEnvConfiguration = file_exists($mainEnvFile) ? require($mainEnvFile) : array();

return CMap::mergeArray(
            array(
        'name' => '',
        'basePath' => 'backend',
        // set parameters
        'params' => $params,
        // preload components required before running applications
        'preload' => array('bootstrap', 'log'),
        'language' => 'en',
        'import' => array(
            'common.components.*',
            'common.extensions.*',
            /* uncomment if required */
            /* 'common.extensions.behaviors.*', */
            /* 'common.extensions.validators.*', */
            'common.models.*',
            // uncomment if behaviors are required
// you can also import a specific one
            /* 'common.extensions.behaviors.*', */
// uncomment if validators on common folder are required
            /* 'common.extensions.validators.*', */
            'application.components.*',
            'application.controllers.*',
            'application.models.*',
            'application.helpers.*',
        ),
        /* uncomment and set if required */
        'modules' => array(
            'gii' => array(
                'class' => 'system.gii.GiiModule',
                'password' => 'clevertech',
                'generatorPaths' => array(
                    'bootstrap.gii'
                )
            ),
            'auth' => array(
                'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.
                'userClass' => 'User', // the name of the user model class.
                'userIdColumn' => 'id', // the name of the user id column.
                'userNameColumn' => 'username', // the name of the user name column.
                'appLayout' => 'application.views.layouts.main', // the layout used by the module.
            ),
        ),
        'components' => array(
            'clientScript' => array(
                'class' => 'application.extensions.minify.EClientScript',
                'combineScriptFiles' => !YII_DEBUG, // By default this is set to true, set this to true if you'd like to combine the script files
                'combineCssFiles' => !YII_DEBUG, // By default this is set to true, set this to true if you'd like to combine the css files
                'optimizeScriptFiles' => !YII_DEBUG, // @since: 1.1
                'optimizeCssFiles' => !YII_DEBUG, // @since: 1.1
            ),
            'request' => array(
                'enableCsrfValidation' => true,
                'enableCookieValidation' => true,
            ),
            'authManager' => array(
                'class' => 'CDbAuthManager',
                'connectionID' => 'db',
                'itemTable' => 'AuthItem',
                'itemChildTable' => 'AuthItemChild',
                'assignmentTable' => 'AuthAssignment',
                'behaviors' => array(
                    'auth' => array(
                        'class' => 'auth.components.AuthBehavior',
                        'admins' => array('admin', 'foo', 'bar'), // users with full access
                    ),
                ),
//                    'behaviors' => array(
//                        'auth' => array(
//                            'class' => 'auth.components.AuthBehavior',
//                        ),
//                    ),
            ),
            'image' => array(
                'class' => 'application.extensions.image.CImageComponent',
                // GD or ImageMagick
                'driver' => 'GD',
            // ImageMagick setup path
            //'params' => array('directory' => '/opt/local/bin'),
            ),
            'email' => array(
                'class' => 'application.extensions.email.Email',
                'delivery' => 'php', //Will use the php mailing function.  
            //May also be set to 'debug' to instead dump the contents of the email into the view
            ),
            'user' => array(
//                    'class' => 'WebUser',
                'class' => 'auth.components.AuthWebUser',
//                    'admins' => array('admin', 'foo', 'bar'), // users with full access
                'allowAutoLogin' => true,
            ),
            /* load bootstrap components */
            'bootstrap' => array(
                'class' => 'common.extensions.bootstrap.components.Bootstrap',
                'responsiveCss' => true,
            ),
            'cache' => array(
                'class' => 'CApcCache',
//                    'class' => 'CFileCache',
            ),
            'errorHandler' => array(
                'errorAction' => 'site/error'
            ),
            'urlManager' => array(
                'urlFormat' => 'path',
                'showScriptName' => false,
                'urlSuffix' => '/',
                'rules' => $params['url.rules']
            ),
            /* make sure you have your cache set correctly before uncommenting */
            'cache' => $params['cache.core'],
            'contentCache' => $params['cache.content']
        ),
            ), CMap::mergeArray($mainEnvConfiguration, $mainLocalConfiguration)
);

但它不起作用错误msg说:

别名“auth.AuthModule”无效。确保它指向现有的PHP文件,并且该文件是可读的。

另外,我不知道从前端和后端上传文件的完美路径是什么?

1 个答案:

答案 0 :(得分:2)

在模块

下更改代码如下
auth' => array(
                'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.
                'class'=>'common.modules.auth.AuthModule', // add this line.. and change AuthModule according to the auth module class name
                'userClass' => 'User', // the name of the user model class.
                'userIdColumn' => 'id', // the name of the user id column.
                'userNameColumn' => 'username', // the name of the user name column.
                'appLayout' => 'application.views.layouts.main', // the layout used by the module.
            ),

希望这会有效..