Yii框架config / main.php不包含与

时间:2015-06-19 12:52:23

标签: php yii vagrant virtualbox gii

我一直在使用yii框架的vagrant,我已经创建了一个虚拟服务器,并且我已将我的YII框架放在那里。它连接到我的数据库,它工作正常,但是当我去index.php?r=gii时,我得到以下

error:Error 403
You are not allowed to access this page.

好吧,我在线查看,也从这个网站上找到了一些解决方案,比如转到config / main.php并从那里更改allowedIPs然而,当我去我的main.php这就是我见:

<?php

/**
 * This is the main Web application configuration.
 *
 * Any writable CWebApplication properties can be configured here.
 * It is constructed the following way:
 *    main.php = return the main settings
 *                  unless overwritten by the local main settings if available
 *                  unless overwritten by the test settings if available
 *                  unless overwritten by the local test settings if available
 * (mergeArray: latter will overwrite the former, see http://www.yiiframework.com/doc/api/1.1/CMap#mergeArray-detail)
 *
 * @author Yii, adapted by Robbert <Paulussen@Momentum-Technologies.nl>
 * @since release 1.0 (sprint 1)
 */
// Set up path variables to reflect the directory structure
// $WEBHOME/                     -- doePath
// $WEBHOME/public/              -- webrootPath
// $WEBHOME/private/protected/   -- protectedPath
// $WEBHOME/private/runtime/     -- runtimePath

$pathToDoeDirectory  = realpath(dirname(__FILE__) . '/../../..');
$privatePath         = $pathToDoeDirectory . '/private/';
$protectedPath       = $pathToDoeDirectory . '/private/protected/';
$runtimePath         = $pathToDoeDirectory . '/private/runtime/';
$publicPath          = $pathToDoeDirectory . '/public/';
$webrootPath         = $publicPath;

/**
 * Namespace MTE
 */
Yii::setPathOfAlias('MTE', $protectedPath);

// used by the themeUrl of widgetFactory settings, in case the DOE is in a subdirectory
$baseUrl = (isset($_SERVER['DOCUMENT_ROOT'])) ? str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath('.')) : '';

//define('EOL','<br/>');
//echo '$pathToCcsDirectory = ' . $pathToCcsDirectory . PHP_EOL;
//echo '$privatePath = ' . $privatePath . PHP_EOL;
//echo '$protectedPath = ' . $protectedPath . PHP_EOL;
//echo '$runtimePath = ' . $runtimePath . PHP_EOL;
//echo '$publicPath = ' . $publicPath . PHP_EOL;
//echo '$webrootPath = ' . $webrootPath . PHP_EOL;
/** the following defines path aliases using:   Yii::setPathOfAlias('local','path/to/local-folder');
 * usage e.g.  ... Yii::getPathOfAlias('runtimePath') ...
 */
Yii::setPathOfAlias('doePath', $pathToDoeDirectory);
Yii::setPathOfAlias('privatePath', $privatePath);
Yii::setPathOfAlias('publicPath', $publicPath);
Yii::setPathOfAlias('protectedPath', $protectedPath);
Yii::setPathOfAlias('runtimePath', $runtimePath);
Yii::setPathOfAlias('webrootPath', $webrootPath);
$config_database = require(dirname(__FILE__) . '/database.php');

$config_main = array(
    'sourceLanguage' => 'en',
    'timeZone'       => 'Europe/Amsterdam',
    'basePath'       => $protectedPath,
    // override the default of Yii
    'runtimePath'    => $runtimePath,
    'name'           => Yii::t('system', 'DOE Web Application'),
    // preloading 'log' component
    'preload'        => array(
        'log',
        'translate',
    ),
    // autoloading model and component classes, Note that importing a directory does not import any of its subdirectories!
    'import' => array(
        'application.components.*',
        'application.models.*',
        'application.modules.rights.*',
        'application.modules.rights.components.*',
        'application.modules.translate.TranslateModule',
    ),
    'modules' => array(
        'translate',
        'rights' => array(
            'install'        => false, // Whether to install rights.
            'userNameColumn' => 'login', // Name of the user name column in the database.
            'userClass'      => 'RightsModuleUser', // extended User model
            'cssFile'        => '/MTE/modules/rights/default.css', // custom css for rights module
        /* more options */
//          'appLayout'          => 'application.views.layouts.main', // Application layout.
//          'authenticatedName'  => 'Authenticated',                // Name of the authenticated user role.
//          'baseUrl'            => '/rights',                      // Base URL for Rights. Change if module is nested.
//          'debug'              => false,                          // Whether to enable debug mode.
//          'displayDescription' => true,                           // Whether to use item description instead of name.
//          'enableBizRule'      => true,                           // Whether to enable authorization item business rules.
//          'enableBizRuleData'  => false,                          // Whether to enable data for business rules.
//          'flashErrorKey'      => 'RightsError',                  // Key to use for setting error flash messages.
//          'flashSuccessKey'    => 'RightsSuccess',                // Key to use for setting success flash messages.
//          'layout'             => 'rights.views.layouts.main',    // Layout to use for displaying Rights.
//          'superuserName'      => 'Admin',                        // Name of the role with super user privileges.
//          'userIdColumn'       => 'id',                           // Name of the user id column in the database.
        ),
        // Whether to enable installer.
        // application components
        'components'     => array(
            'user' => array(
                'class'          => 'WebUser',
                /* enable cookie-based authentication */
                'allowAutoLogin' => true,
                /* @see http://www.yiiframework.com/doc/guide/1.1/en/topics.auth */
                'loginUrl'       => array('/site/login'),
            ),
            'authManager' => array(
                'class'          => 'RDbAuthManager',
                'connectionID'   => 'db',
                'defaultRoles'   => array('authenticated', 'user'),
            ),
            'messages' => array(
                'class'                  => 'CDbMessageSource',
                'onMissingTranslation'   => array('TranslateModule',
                    'missingTranslation',
                ),
                'translate' => array(
                    'class'              => 'translate.components.MPTranslate',
                    'acceptedLanguages'  => array(
                        'en'         => 'English',
                        'nl'         => 'Nederlands',
                    ),
                ),
            ),
            //use component to store the cookies
            'Cookies'    => array(
                'class'      => 'application.components.CookiesHelper'
            ),
            // uncomment the following to enable URLs in path-format
            'urlManager' => array(
                'urlFormat'      => 'path',
                'showScriptName' => false,
                'rules'          => array(
                    '<controller:\w+>/<id:\d+>'              => '<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',
                ),
            ),
            'errorHandler'                           => array(
                // use 'site/error' action to display errors
                'errorAction'    => 'site/error',
            ),
            'log'            => array(
                'class'  => 'CLogRouter',
                'routes' => array(
                    array(
                        'class'  => 'CFileLogRoute',
                        'levels' => 'info, warning, error',
                    ),
                ),
            ),
        ),
    ),
    /** application-level parameters that can be accessed
     *  using Yii::app()->params['paramName']
     */
    'params' => array(
        // this is used in contact page
        'adminEmail'         => 'ddd@sdaadad-dsdsdsa.nl',
        'cookie_duration'    => 3600 * 24 * 30,
        'composer.callbacks' => array(
            // args for Yii command runner
            'yiisoft/yii-install' => array('yiic', 'webapp', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'),
            'post-update' => array('yiic', 'migrate'),
            'post-install' => array('yiic', 'migrate'),
        ),
    ),
);
$mainDbIncluded = CMap::mergeArray($config_database, $config_main);

// include and merge local main config if it exists
if (file_exists(dirname(__FILE__) . '/main-local.php'))
{
    return CMap::mergeArray($mainDbIncluded, include(dirname(__FILE__) . '/main-local.php'));
}
// otherwise just load the main config file
return $mainDbIncluded;

这是我的main-local.php:

<?php

/**
 * This is the main Web application configuration.
 *
 * This file is local to the developers machine.
 */
Yii::setPathOfAlias('MTe', '/var/www/private/protected/');
// the following lines may not run when in production mode, so they should be in a ..-local.php
defined('YII_DEBUG') or define('YII_DEBUG', true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 5);

return array(
    'modules' => array(
        // uncomment the following to enable the Gii tool
        'gii' => array(
            'class'      => 'system.gii.GiiModule',
            'password'   => 'password',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'  => array('127.0.0.1', '::1'),
        ),
    ),
    'components' => array(
//      'urlManager' => array(
//          'urlFormat'      => 'path',
//          'showScriptName' => false,
//      ),
//      'cache'  => array(
//          'class'                  => 'CDbCache',
//          'connectionID'           => 'db',
//          'autoCreateCacheTable'   => true,
//      ),
//      'db'     => array(

//          'schemaCachingDuration' => 3600,
//      ),
        'log' => array(
            'class'  => 'CLogRouter',
            'routes' => array(
                array(
                    'class'  => 'CFileLogRoute',
                    'levels' => 'trace, info, warning, error',
                //       'categories' => 'system.*',
                ),
                array(
                    'class'  => 'CWebLogRoute',
                    'levels' => 'error, warning, info, trace',
                ),
                /*
                  array(
                  'class' => 'CEmailLogRoute',
                  'levels' => 'error, warning',
                  'emails' => 'sddsd@m-sdsdsd.nl',
                  ),
                 */
                array(
                    'class'              => 'CProfileLogRoute',
                ),
            ),
        ),
    ),
    'params'             => array(
        'adminEmail' => 'sssss@m-sdsdsdsd.nl', // this is used in contact page
    ),
);

我如何解决这里的gii问题?

1 个答案:

答案 0 :(得分:2)

你错了! 您允许每个人访问GII。任何人都可以重写你的课程......

将您的计算机地址或网络地址掩码写入ipFilter参数。

另一种方法是在完成工作后注释掉GII模块。