Commit 520011ff by Qiang Xue

Fixes #3088: The debug and gii modules will manage their own URL rules now

parent 507a6f10
......@@ -6,6 +6,8 @@ if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
......
......@@ -6,6 +6,8 @@ if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
......
......@@ -41,6 +41,8 @@ if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
......
......@@ -8,7 +8,7 @@ as well as complete CRUD controllers.
Installing and configuring
--------------------------
Gii is an offical Yii extension. The preferred way to install this extension is through
Gii is an official Yii extension. The preferred way to install this extension is through
[composer](http://getcomposer.org/download/).
You can either run this command:
......@@ -26,11 +26,14 @@ Or you can add this code to the require section of your `composer.json` file:
Once the Gii extension has been installed, you enable it by adding these lines to your application configuration file:
```php
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
// ...
],
]
// ...
];
```
You can then access Gii through the following URL:
......@@ -39,7 +42,15 @@ You can then access Gii through the following URL:
http://localhost/path/to/index.php?r=gii
```
> Note: if you are accessing gii from an IP address other than localhost, access will be denied by default. To circumvent that default, add the allowed IP addressess to the configuration:
If you have enabled pretty URLs, you may use the following URL:
```
http://localhost/path/to/index.php/gii
```
> Note: if you are accessing gii from an IP address other than localhost, access will be denied by default.
> To circumvent that default, add the allowed IP addresses to the configuration:
>
```php
'gii' => [
......@@ -55,11 +66,12 @@ In basic application template configuration structure is a bit different so Gii
```php
// ...
if (YII_ENV_DEV)
{
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module'; // <--- here
}
```
......@@ -67,11 +79,12 @@ if (YII_ENV_DEV)
So in order to adjust IP address you need to do it like the following:
```php
if (YII_ENV_DEV)
{
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
......@@ -100,8 +113,8 @@ By default there are the following generators available:
After choosing a generator by clicking on the "Start" button you will see a form that allows you to configure the
parameters of the generator. Fill out the form according to your needs and press the "Preview" button to get a
preview of the code that gii is about to generated. Dependend on the generator you chose and whether the files
already existed or not you will get an ouput similar to what you see in the following picuture:
preview of the code that gii is about to generated. Depending on the generator you chose and whether the files
already existed or not, you will get an output similar to what you see in the following picture:
![Gii preview](images/gii-preview.png)
......@@ -143,7 +156,9 @@ If you open a folder `@app\vendor\yiisoft\yii2-gii\generators`, you'll see six f
```
This is name generator. If you open any of these folders, you can see the folder `default`. This folder is name of the template.
Copy folder `@app\vendor\yiisoft\yii2-gii\generators\crud\default` to another location, for example `@app\myTemplates\crud\`. Now open this folder and modify any template to fit your desires, for example, add `errorSummary` in `views\_form.php`:
Copy folder `@app\vendor\yiisoft\yii2-gii\generators\crud\default` to another location, for example `@app\myTemplates\crud\`.
Now open this folder and modify any template to fit your desires, for example, add `errorSummary` in `views\_form.php`:
```php
<?php
//...
......@@ -156,19 +171,21 @@ Copy folder `@app\vendor\yiisoft\yii2-gii\generators\crud\default` to another lo
} ?>
//...
```
All, in fact our template ready. Now you need to tell GII about our template.The setting is made in the config file:
Now you need to tell GII about our template.The setting is made in the config file:
```php
//config/web.php for basic app
//..
// config/web.php for basic app
// ...
if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
'generators'=>[ //here
'crud'=>[ //name generator
'class'=>'yii\gii\generators\crud\Generator', //class generator
'templates'=>[ //setting for out tempates
'myCrud'=>'@app\myTemplates\crud\default', //name tempate => path to template
'generators' => [ //here
'crud' => [ //name generator
'class' => 'yii\gii\generators\crud\Generator', //class generator
'templates' => [ //setting for out templates
'myCrud' => '@app\myTemplates\crud\default', //name template => path to template
]
]
],
......@@ -180,7 +197,10 @@ Open the CRUD generator and you will see that in the field `Code Template` of fo
Creating your own generators
----------------------------
Open the folder of any generator and you will see two files `form.php` and `Generator.php`. One is the form, the second is the class generator. For create your own generator, you need to create or override these classes in any folder. Again as in the previous paragraph customize configuration:
Open the folder of any generator and you will see two files `form.php` and `Generator.php`.
One is the form, the second is the class generator. For create your own generator, you need to create or
override these classes in any folder. Again as in the previous paragraph customize configuration:
```php
//config/web.php for basic app
//..
......@@ -188,11 +208,11 @@ if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
'generators'=>[
'myCrud'=>[
'class'=>'app\myTemplates\crud\Generator',
'templates'=>[
'my'=>'@app/myTemplates/crud/default',
'generators' => [
'myCrud' => [
'class' => 'app\myTemplates\crud\Generator',
'templates' => [
'my' => '@app/myTemplates/crud/default',
]
]
],
......@@ -204,6 +224,7 @@ if (YII_ENV_DEV) {
// @app/myTemplates/crud/Generator.php
<?php
namespace app\myTemplates\crud;
class Generator extends \yii\gii\Generator
{
public function getName()
......@@ -218,7 +239,7 @@ class Generator extends \yii\gii\Generator
// ...
}
```
Open gii Module and You will see that added a new generator.
Open Gii Module and you will see a new generator appears in it.
......@@ -4,6 +4,7 @@ Yii Framework 2 debug extension Change Log
2.0.0-rc under development
--------------------------
- Enh #3088: The debug module will manage their own URL rules now (qiangxue)
- Enh #3103: debugger panel is now not displayed when printing a page (githubjeka)
- Enh #3108: Added `yii\debug\Module::enableDebugLogs` to disable logging debug logs by default (qiangxue)
......
......@@ -117,6 +117,13 @@ class Module extends \yii\base\Module implements BootstrapInterface
$app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) {
$app->getView()->on(View::EVENT_END_BODY, [$this, 'renderToolbar']);
});
$app->getUrlManager()->addRules(
[
$this->id => $this->id,
$this->id . '/<controller:\w+>/<action:\w+>' => $this->id . '/<controller>/<action>',
]
);
}
/**
......
......@@ -36,7 +36,7 @@ return [
'bootstrap' => ['debug'],
'modules' => [
'debug' => 'yii\debug\Module',
...
// ...
],
...
];
......
......@@ -4,7 +4,7 @@ Yii Framework 2 gii extension Change Log
2.0.0-rc under development
--------------------------
- no changes in this release.
- Enh #3088: The gii module will manage their own URL rules now (qiangxue)
2.0.0-beta April 13, 2014
......
......@@ -8,6 +8,7 @@
namespace yii\gii;
use Yii;
use yii\base\BootstrapInterface;
use yii\web\ForbiddenHttpException;
/**
......@@ -17,7 +18,7 @@ use yii\web\ForbiddenHttpException;
*
* ~~~
* return [
* ......
* 'bootstrap' => ['gii'],
* 'modules' => [
* 'gii' => ['class' => 'yii\gii\Module'],
* ],
......@@ -32,26 +33,13 @@ use yii\web\ForbiddenHttpException;
* 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]] and you have defined
* custom URL rules or enabled [[\yii\web\UrlManager::enableStrictParsing], you may need to add
* the following URL rules at the beginning of your URL rule set in your application configuration
* in order to access Gii:
*
* ~~~
* 'rules' => [
* 'gii' => 'gii',
* 'gii/<controller>' => 'gii/<controller>',
* 'gii/<controller>/<action>' => 'gii/<controller>/<action>',
* ...
* ],
* ~~~
*
* You can then access Gii via URL: `http://localhost/path/to/index.php/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`
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Module extends \yii\base\Module
class Module extends \yii\base\Module implements BootstrapInterface
{
/**
* @inheritdoc
......@@ -90,15 +78,19 @@ class Module extends \yii\base\Module
*/
public $newDirMode = 0777;
/**
* @inheritdoc
*/
public function init()
public function bootstrap($app)
{
parent::init();
foreach (array_merge($this->coreGenerators(), $this->generators) as $id => $config) {
$this->generators[$id] = Yii::createObject($config);
}
$app->getUrlManager()->addRules(
[
$this->id => $this->id . '/default/index',
$this->id . '/<id:\w+>' => $this->id . '/default/view',
$this->id . '/<controller:\w+>/<action:\w+>' => $this->id . '/<controller>/<action>',
]
);
}
/**
......@@ -106,6 +98,10 @@ class Module extends \yii\base\Module
*/
public function beforeAction($action)
{
foreach (array_merge($this->coreGenerators(), $this->generators) as $id => $config) {
$this->generators[$id] = Yii::createObject($config);
}
if ($this->checkAccess()) {
return parent::beforeAction($action);
} else {
......
......@@ -32,11 +32,12 @@ Once the extension is installed, simply modify your application configuration as
```php
return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
...
// ...
],
...
// ...
];
```
......@@ -45,3 +46,9 @@ You can then access Gii through the following URL:
```
http://localhost/path/to/index.php?r=gii
```
or if you have enabled pretty URLs, you may use the following URL:
```
http://localhost/path/to/index.php/gii
```
......@@ -11,6 +11,7 @@ Yii Framework 2 Change Log
- Bug #3125: `yii\console\controllers\AssetController` now respects data URL resources (klimov-paul)
- Bug #3128: Fixed the bug that `defaultRoles` set in RBAC manager was not working as specified (qiangxue)
- Bug #3153: Fixed the bug that using "between" operator to build a SQL query will cause a PHP notice (gonimar)
- Enh #3088: The debug and gii modules will manage their own URL rules now (hiltonjanfield, qiangxue)
- Enh #3103: debugger panel is now not displayed when printing a page (githubjeka)
- Enh #3108: Added `yii\debug\Module::enableDebugLogs` to disable logging debug logs by default (qiangxue)
- Enh #3132: `yii\rbac\PhpManager` now supports more compact data file format (qiangxue)
......
......@@ -156,14 +156,21 @@ class UrlManager extends Component
/**
* Adds additional URL rules.
*
* This method will call [[buildRules()]] to parse the given rule declarations and then append or insert
* them to the existing [[rules]].
*
* Note that if [[enablePrettyUrl]] is false, this method will do nothing.
*
* @param array $rules the new rules to be added. Each array element represents a single rule declaration.
* Please refer to [[rules]] for the acceptable rule format.
* @param boolean $append whether to add the new rules by appending them to the end of the existing rules.
*/
public function addRules($rules, $append = true)
{
if (!$this->enablePrettyUrl) {
return;
}
$rules = $this->buildRules($rules);
if ($append) {
$this->rules = array_merge($this->rules, $rules);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment