To use Gii, include it as a module in the application configuration like the following: ~~~ return [ 'bootstrap' => ['gii'], 'modules' => [ 'gii' => ['class' => 'yii\gii\Module'], ], ] ~~~ Because Gii generates new code files on the server, you should only use it on your own development machine. To prevent other people from using this module, by default, Gii can only be accessed by localhost. You may configure its [[allowedIPs]] property if you want to make it accessible on other machines. With the above configuration, you will be able to access GiiModule in your browser using the URL http://localhost/path/to/index.php?r=gii If your application enables [[\yii\web\UrlManager::enablePrettyUrl|pretty URLs]], you can then access Gii via URL: http://localhost/path/to/index.php/gii
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Module, implements yii\base\BootstrapInterface
Beispiel #1
0
 public function bootstrap($app)
 {
     /** @var Module $module */
     if ($app->hasModule('cms') && ($module = $app->getModule('cms')) instanceof Module) {
         $classMap = array_merge($this->classMap, $module->classMap);
         foreach (array_keys($this->classMap) as $item) {
             $className = '\\nullref\\cms\\models\\' . $item;
             $cmsClass = $className::className();
             $definition = $classMap[$item];
             Yii::$container->set($cmsClass, $definition);
         }
         if ($app instanceof WebApplication) {
             $prefix = $app->getModule('cms')->urlPrefix;
             $app->urlManager->addRules([Yii::createObject(['class' => PageUrlRule::className(), 'pattern' => $prefix . '/<route:[_a-zA-Z0-9-/]+>'])]);
             if (!isset($app->controllerMap['elfinder-backend'])) {
                 $app->controllerMap['elfinder-backend'] = ['class' => 'mihaildev\\elfinder\\Controller', 'user' => 'admin', 'access' => ['@'], 'disabledCommands' => ['netmount'], 'roots' => [['path' => 'uploads', 'name' => 'Uploads']]];
             }
             $app->i18n->translations['cms*'] = ['class' => PhpMessageSource::className(), 'basePath' => '@nullref/cms/messages'];
         }
         if (YII_ENV_DEV) {
             Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
                 /** @var Gii $gii */
                 $gii = $event->sender;
                 $gii->generators['block-migration-generator'] = ['class' => 'nullref\\cms\\generators\\block_migration\\Generator'];
                 $gii->generators['block-generator'] = ['class' => 'nullref\\cms\\generators\\block\\Generator'];
                 $gii->generators['pages-migration-generator'] = ['class' => 'nullref\\cms\\generators\\pages_migration\\Generator'];
             });
         }
     }
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 protected function coreGenerators()
 {
     $res = parent::coreGenerators();
     $res['extension']['class'] = 'hiqdev\\hiqgii\\generators\\extension\\Generator';
     $res['module']['class'] = 'hiqdev\\hiqgii\\generators\\module\\Generator';
     return $res;
 }
Beispiel #3
0
 public function init()
 {
     parent::init();
     if (\Yii::$app->cms->giiEnabled == Cms::BOOL_N) {
         $this->allowedIPs = [""];
     } else {
         //TODO:add merge settings
         $this->allowedIPs = explode(",", \Yii::$app->cms->giiAllowedIPs);
     }
     $class = new \ReflectionClass(\yii\gii\Module::className());
     $dir = dirname($class->getFileName());
     $this->setBasePath($dir);
 }
Beispiel #4
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app instanceof WebApplication) {
     }
     if ($app instanceof ConsoleApplication) {
         $app->controllerMap['module'] = ['class' => 'nullref\\core\\console\\ModuleController'];
         $app->controllerMap['modules-migrate'] = ['class' => 'nullref\\core\\console\\ModulesMigrateController'];
         $app->controllerMap['env'] = ['class' => 'nullref\\core\\console\\EnvController'];
         $app->getModule('core')->controllerMap['migrate'] = ['class' => 'nullref\\core\\console\\MigrateController'];
     }
     if (YII_ENV_DEV && class_exists('yii\\gii\\Module')) {
         Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
             /** @var Gii $gii */
             $gii = $event->sender;
             $gii->generators['relation-migration'] = ['class' => 'nullref\\core\\generators\\migration\\Generator'];
         });
     }
 }
Beispiel #5
0
<?php

$params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
return ['id' => 'app-backend', 'name' => 'Toyplan Admin', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\\controllers', 'bootstrap' => ['log'], 'modules' => ['gii' => ['class' => \yii\gii\Module::className(), 'allowedIPs' => ['*']], 'gridview' => ['class' => '\\kartik\\grid\\Module']], 'components' => ['request' => ['class' => 'common\\components\\Request', 'web' => '/backend/web', 'adminUrl' => '/admin'], 'urlManager' => ['class' => 'yii\\web\\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' => false, 'rules' => ['' => 'site/index', ['pattern' => '<slug>', 'route' => 'category/index', 'suffix' => '/'], '<module:\\w+>/<controller:\\w+>/<action:[\\w\\-]+>' => '<module>/<controller>/<action>']], 'user' => ['identityClass' => 'common\\models\\User', 'enableAutoLogin' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'errorHandler' => ['errorAction' => 'site/error']], 'params' => $params];
Beispiel #6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->setBasePath('@vendor/yiisoft/yii2-gii');
 }
Beispiel #7
0
<?php

$params = (require __DIR__ . '/params.php');
$config = ['id' => 'basic', 'language' => 'ru', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'components' => ['request' => ['cookieValidationKey' => 'O_RRcy_Mh_JvD8bbXBooCDZtZwNjRLYn'], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'user' => ['identityClass' => 'app\\models\\User', 'enableAutoLogin' => true], 'errorHandler' => ['errorAction' => 'site/error'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => require __DIR__ . '/db.php', 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['<_c:[\\w\\-]+>/<id:\\d+>' => '<_c>/view', '<_c:[\\w\\-]+>' => '<_c>/index', '<_c:[\\w\\-]+>/<_a:[\\w\\-]+>/<id:\\d+>' => '<_c>/<_a>']]], '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['bootstrap'][] = 'gii';
    $config['modules']['gii'] = ['class' => \yii\gii\Module::className()];
}
return $config;
Beispiel #8
0
 public function init()
 {
     $this->controllerNamespace = 'yii\\gii\\controllers';
     parent::init();
 }
Beispiel #9
0
<?php

/**
 * Created by PhpStorm.
 * User: bug
 * Date: 22.06.15
 * Time: 18:48
 */
$config = ['components' => ['request' => ['cookieValidationKey' => 'tZ_RrBX7OvzjL1mHW1d0zE5XeI-O3RkX']]];
if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = ['class' => \yii\debug\Module::className(), 'allowedIPs' => ['*']];
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = ['class' => \yii\gii\Module::className(), 'allowedIPs' => ['*']];
}
return $config;
Beispiel #10
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     /** @var Module $module */
     if (($module = $app->getModule('admin')) == null || !$module instanceof Module) {
         return;
     }
     $class = 'nullref\\admin\\models\\Admin';
     $definition = $module->adminModel;
     if ($module->enableRbac) {
         $module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
     }
     Yii::$container->set($class, $definition);
     $className = is_array($definition) ? $definition['class'] : $definition;
     Event::on(AdminQuery::className(), AdminQuery::EVENT_INIT, function (Event $e) use($class, $className) {
         if ($e->sender->modelClass == $class) {
             $e->sender->modelClass = $className;
         }
     });
     /** I18n */
     if (!isset($app->get('i18n')->translations['admin*'])) {
         $app->i18n->translations['admin*'] = ['class' => PhpMessageSource::className(), 'basePath' => '@nullref/admin/messages'];
     }
     if ($app instanceof WebApplication) {
         Yii::$app->setComponents(['admin' => ['class' => 'nullref\\admin\\components\\User', 'identityClass' => $className, 'loginUrl' => ['admin/login']]]);
         $app->urlManager->addRules(['/admin/login' => '/admin/main/login']);
         $app->urlManager->addRules(['/admin/logout' => '/admin/main/logout']);
         Event::on(BaseModule::className(), BaseModule::EVENT_BEFORE_ACTION, function () use($module) {
             if (Yii::$app->controller instanceof IAdminController) {
                 /** @var Controller $controller */
                 $controller = Yii::$app->controller;
                 $controller->layout = $module->layout;
                 if ($controller->module != $module) {
                     $controller->module->setLayoutPath($module->getLayoutPath());
                 }
                 if (!isset($controller->behaviors()['access'])) {
                     $controller->attachBehavior('access', AccessControl::className());
                 }
                 Yii::$app->errorHandler->errorAction = $module->errorAction;
             }
         });
     } elseif ($app instanceof ConsoleApplication) {
         if ($module !== null) {
             /** @var Module $module */
             if ($module->enableRbac) {
                 $module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
             }
         }
     }
     Event::on(Module::className(), Module::EVENT_BEFORE_INIT, function (Event $event) use($app) {
         $module = $event->sender;
         /** @var Module $module */
         if ($module->enableRbac) {
             if ($app instanceof ConsoleApplication) {
                 $module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
             }
             $module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
         }
     });
     if (YII_ENV_DEV && class_exists('yii\\gii\\Module')) {
         Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
             /** @var Gii $gii */
             $gii = $event->sender;
             $gii->generators['crud'] = ['class' => 'yii\\gii\\generators\\crud\\Generator', 'templates' => ['admin-crud' => '@nullref/admin/generators/crud/admin']];
             $gii->generators['stuff'] = ['class' => 'nullref\\admin\\generators\\stuff\\Generator', 'templates' => ['default' => '@nullref/admin/generators/stuff/default']];
         });
     }
 }
Beispiel #11
0
 public function init()
 {
     parent::init();
 }
Beispiel #12
0
 /**
  * @inheritdoc
  */
 protected function coreGenerators()
 {
     return array_merge(parent::coreGenerators(), ['base_model' => ['class' => 'yii\\gii\\plus\\generators\\base\\model\\Generator'], 'custom_model' => ['class' => 'yii\\gii\\plus\\generators\\custom\\model\\Generator'], 'fixture' => ['class' => 'yii\\gii\\plus\\generators\\fixture\\Generator']]);
 }