Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 2.2
Browse files Browse the repository at this point in the history
* upstream/master:
  Remove useless import of `Yii` from CRUD generator search model template
  Fixes yiisoft#379: Fixed bug in view page where delete button not work well
  Fixes yiisoft#366: Option to allow standardized class names capitals in model generator
  Fixes yiisoft#327: Fixed bug in Model generator when $baseClass is an abstract class
  Fixes yiisoft#366: Better class and file names for uppercase tables
  Update composer.json (yiisoft#364)
  Fix codestyle (yiisoft#362)
  prepare for next release
  release version 2.0.7
  Register CSRF meta-tags dynamically
  Updated CHANGELOG [ci skip]
  Fixed rules generation for JSON columns
  Removed redundant line from license [skip ci]
  added database version to issue template (yiisoft#352) [skip ci]
  docs/guide-ja revised [ci skip] (yiisoft#349)
  Updated issue template [skip ci]
  Fixes yiisoft#185: Fix bug in Model generators when FKs pointing to non-existing tables
  Fixes yiisoft#340: Fix bug in CRUD SearchModel generator
  Require Yii 2.0.14 (yiisoft#339)

Conflicts:
	composer.json
  • Loading branch information
lav45 committed Oct 24, 2018
2 parents 9b3c6d0 + 6d30fa9 commit 9a9049e
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 63 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
Please use this issue tracker for bugs and feature requests only. In case you need support please use one of
Yii communities listed at https://github.com/yiisoft/yii2/wiki/communities
-->

### What steps will reproduce the problem?

### What's expected?
Expand All @@ -11,4 +16,5 @@
| ---------------- | ---
| Yii version |
| PHP version |
| Database version |
| Operating system |
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
Yii Framework 2 gii extension Change Log
========================================

2.0.7 under development
2.0.8 under development
-----------------------

- Bug #379: Fixed bug in view page where delete button not work well (zacksleo)
- Bug #327: Fixed bug in Model generator when $baseClass is an abstract class (rhertogh)
- Enh #366: Option to allow standardized class names capitals in model generator (slinstj)
- Enh #378: Remove useless import of `Yii` from CRUD generator search model template (CeBe)


2.0.7 May 3, 2018
-----------------

- Bug #185: Fixed bug in Model generators when FKs pointing to non-existing tables (adipriyantobpn)
- Bug #328: Fixed bug in CRUD update view generator (ricpelo)
- Bug #333: Fixed incorrect validation rule for TINYINT column type (nostop8)
- Bug #328: Fix bug in CRUD update view generator (ricpelo)
- Bug #340: Fixed bug in CRUD SearchModel generator (JeanWolf)
- Bug #351: Fixed incorrect validation rule for JSON column type (silverfire)


2.0.6 December 23, 2017
Expand Down
3 changes: 0 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
The Yii framework is free software. It is released under the terms of
the following BSD License.

Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.

Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"require": {
"php": ">=5.5",
"yiisoft/yii2": "2.0.*",
"yiisoft/yii2": "~2.0.14",
"yiisoft/yii2-bootstrap4": "1.0.x-dev",
"phpspec/php-diff": ">=1.0.2",
"bower-asset/typeahead.js": "0.10.* | ~0.11.0",
Expand All @@ -48,6 +48,14 @@
"dev-master": "2.2.x-dev"
}
},
"config": {
"fxp-asset": {
"installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
},
"repositories": [
{
"type": "composer",
Expand Down
6 changes: 3 additions & 3 deletions docs/guide-ja/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Yii 2 Gii エクステンション
==========================

このエクステンションは、Yii 2 アプリケーションのために、Gii と呼ばれるウェブベースのコードジェネレータを提供します
このエクステンションは、Yii 2 アプリケーションのために、Gii と呼ばれるウェブ・ベースのコード・ジェネレータを提供します
Gii を使うと、モデル、フォーム、モジュール、CRUD などを素早く生成することが出来ます。

Gii はウェブベースのインタフェイスを提供しており、あなたの望みのコードを対話的に生成することが出来ます。
Gii は、また、ほとんどの時間はコンソールウィンドウで仕事をすることを好む人たちのために、コマンドラインのインタフェイスも提供しています。
Gii はウェブ・ベースのインタフェイスを提供しており、あなたの望みのコードを対話的に生成することが出来ます。
Gii は、また、ほとんどの時間はコンソール・ウィンドウで仕事をすることを好む人たちのために、コマンドラインのインタフェイスも提供しています。


始めよう
Expand Down
20 changes: 10 additions & 10 deletions docs/guide-ja/basic-usage.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
基本的な使用方法
================

Gii にアクセスすると、最初に、ジェネレータを選択できるエントリページが開かれます
Gii にアクセスすると、最初に、ジェネレータを選択できるエントリ・ページが開かれます

![Gii エントリページ](images/gii-entry.png)
![Gii エントリ・ページ](images/gii-entry.png)

デフォルトでは、以下のジェネレータを利用できます。

- **モデルジェネレータ** - このジェネレータは、指定したデータベーステーブルの ActiveRecord クラスを生成します。
- **CRUD ジェネレータ** - このジェネレータは、指定されたデータモデルの CRUD 操作 (作成・読み出し・更新・削除) を実装するコントローラとビューを生成します。
- **コントローラジェネレータ** - このジェネレータは、新しいコントローラのクラスと、一つまたはいくつかのコントローラアクションおよびそれに対応するビューを迅速に生成するのを手助けしてくれます
- **フォームジェネレータ** - このジェネレータは、指定されたモデルクラスのための、入力を収集するフォームを表示するビュースクリプトを生成します
- **モジュールジェネレータ** - このジェネレータは、Yii のモジュールが必要とするコードのスケルトンを生成するのを手助けしてくれます。
- **エクステンションジェネレータ** - このジェネレータは、Yii のエクステンションが必要とするファイルの生成を手助けしてくれます。
- **モデルジェネレータ** - このジェネレータは、指定したデータベース・テーブルの ActiveRecord クラスを生成します。
- **CRUD ジェネレータ** - このジェネレータは、指定されたデータ・モデルの CRUD 操作 (作成・読み出し・更新・削除) を実装するコントローラとビューを生成します。
- **コントローラ・ジェネレータ** - このジェネレータは、新しいコントローラのクラスと、一つまたはいくつかのコントローラ・アクションおよびそれに対応するビューを迅速に生成するのを手助けしてくれます
- **フォーム・ジェネレータ** - このジェネレータは、指定されたモデル・クラスのための、入力を収集するフォームを表示するビュー・スクリプトを生成します
- **モジュール・ジェネレータ** - このジェネレータは、Yii のモジュールが必要とするコードのスケルトンを生成するのを手助けしてくれます。
- **エクステンション・ジェネレータ** - このジェネレータは、Yii のエクステンションが必要とするファイルの生成を手助けしてくれます。

"Start" ボタンをクリックしてジェネレータを選択すると、ジェネレータのパラメータを構成するためのフォームが表示されます。
あなたの要求を満たすようにフォームに入力して "Preview" ボタンをクリックすると、Gii が生成しようとしているコードのプレビューが出来ます。
Expand All @@ -24,14 +24,14 @@ Gii にアクセスすると、最初に、ジェネレータを選択できる
ファイルが既に存在する場合は、既存のコードと生成されるコードのどこが異なるかを示す差分ビューも提供されます。
その場合は、どのファイルを上書きし、どのファイルを上書きしないかを選択することも出来ます。

> Tip: データベースに変更を加えた後で、モデルジェネレータを使ってモデルを更新したい場合は、Gii のプレビューからコードをコピーして、あなたのコードに変更をマージすることが出来ます。
> Tip: データベースに変更を加えた後で、モデル・ジェネレータを使ってモデルを更新したい場合は、Gii のプレビューからコードをコピーして、あなたのコードに変更をマージすることが出来ます。
PHPStorm の [クリップボードと比較](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html) のような IDE の機能を使うと良いでしょう。
[Aptana Studio](http://www.aptana.com/products/studio3/download)[Eclipse](http://www.eclipse.org/pdt/) ベースのエディタも [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/) を使って [クリップボードと比較](http://andrei.gmxhome.de/anyedit/examples.html) をすることが出来ます。
この機能を使うと、関係のある変更だけを取り込んで、あなた自身のコードを取り消すような他の変更は放っておくことが出来ます。

コードをレビューして、生成すべきファイルを選択し、"Generate" ボタンをクリックするとファイルが生成されます。
すべてうまく行けば、これで終りです。
Gii がファイルを生成できないというエラーが出た場合は、ウェブサーバがファイルを作成してディレクトリに書き込むことが出来るように、ディレクトリのアクセス権限を修正しなければなりません。
Gii がファイルを生成できないというエラーが出た場合は、ウェブ・サーバがファイルを作成してディレクトリに書き込むことが出来るように、ディレクトリのアクセス権限を修正しなければなりません。

> Note: Gii によって生成されるコードは、あなたの要求に従って修正すべきテンプレートに過ぎません。
Gii は新しいものを素早く作成する手助けをするために存在するものですが、そのまま使用できるコードを作成するようなものではありません。
Expand Down
12 changes: 6 additions & 6 deletions docs/guide-ja/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ http://localhost/path/to/index.php?r=gii
http://localhost/path/to/index.php/gii
```

> Note: ローカルホスト以外の IP から Gii にアクセスしようとすると、デフォルトでは、アクセスが拒否されます。
> Note: ローカル・ホスト以外の IP から Gii にアクセスしようとすると、デフォルトでは、アクセスが拒否されます。
> このデフォルトを回避するためには、許可される IP アドレスを構成情報に追加してください。
>
```php
Expand All @@ -56,26 +56,26 @@ http://localhost/path/to/index.php/gii
],
```

コンソールアプリケーションの構成情報において同じように Gii を構成すると、次のようにして、コマンドウィンドウから Gii にアクセスすることが出来ます。
コンソールアプリケーションの構成情報において同じように Gii を構成すると、次のようにして、コマンド・ウィンドウから Gii にアクセスすることが出来ます。

```
# パスをアプリケーションのベースパスに変更
# パスをアプリケーションのベース・パスに変更
cd path/to/AppBasePath
# Gii に関するヘルプ情報を表示
yii help gii
# Gii のモデルジェネレータに関するヘルプ情報を表示
# Gii のモデル・ジェネレータに関するヘルプ情報を表示
yii help gii/model
# city テーブルから City モデルを生成
yii gii/model --tableName=city --modelClass=City
```


### ベーシックアプリケーション
### ベーシック・アプリケーション

ベーシックプロジェクトテンプレートの構成情報の構造は少し違っており、Gii は `config/web.php` の中で構成しなければなりません。
ベーシック・プロジェクト・テンプレートの構成情報の構造は少し違っており、Gii は `config/web.php` の中で構成しなければなりません。

```php
// ...
Expand Down
2 changes: 1 addition & 1 deletion docs/guide-ja/topics-creating-your-own-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
==================================

どれでもジェネレータのフォルダを開くと、`form.php``Generator.php` の二つのファイルがあります。
一つ目はフォームで、二番目のものがジェネレータクラスです
一つ目はフォームで、二番目のものがジェネレータ・クラスです
あなた自身のジェネレータを作成するためには、これらのクラスをどこかのフォルダで作成またはオーバーライドする必要があります。
ここでも、前の節でしたのと同じように、構成情報をカスタマイズします。

Expand Down
2 changes: 1 addition & 1 deletion docs/guide-ja/topics-creating-your-own-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (YII_ENV_DEV) {
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
'generators' => [ // ここ
'crud' => [ // ジェネレータの名前
'class' => 'yii\gii\generators\crud\Generator', // ジェネレータクラス
'class' => 'yii\gii\generators\crud\Generator', // ジェネレータ・クラス
'templates' => [ //setting for out templates
'myCrud' => '@app/myTemplates/crud/default', // テンプレート名 => テンプレートへのパス
]
Expand Down
24 changes: 12 additions & 12 deletions src/CodeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public function save()
}
if (@file_put_contents($this->path, $this->content) === false) {
return "Unable to write the file '{$this->path}'.";
} else {
$mask = @umask(0);
@chmod($this->path, $module->newFileMode);
@umask($mask);
}

$mask = @umask(0);
@chmod($this->path, $module->newFileMode);
@umask($mask);

return true;
}

Expand All @@ -111,9 +111,9 @@ public function getRelativePath()
{
if (strpos($this->path, Yii::$app->basePath) === 0) {
return substr($this->path, strlen(Yii::$app->basePath) + 1);
} else {
return $this->path;
}

return $this->path;
}

/**
Expand All @@ -123,9 +123,9 @@ public function getType()
{
if (($pos = strrpos($this->path, '.')) !== false) {
return substr($this->path, $pos + 1);
} else {
return 'unknown';
}

return 'unknown';
}

/**
Expand All @@ -145,9 +145,9 @@ public function preview()
return highlight_string($this->content, true);
} elseif (!in_array($type, ['jpg', 'gif', 'png', 'exe'])) {
return nl2br(Html::encode($this->content));
} else {
return false;
}

return false;
}

/**
Expand All @@ -162,9 +162,9 @@ public function diff()
return false;
} elseif ($this->operation === self::OP_OVERWRITE) {
return $this->renderDiff(file($this->path), $this->content);
} else {
return '';
}

return '';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ public function getTemplatePath()
{
if (isset($this->templates[$this->template])) {
return $this->templates[$this->template];
} else {
throw new InvalidConfigException("Unknown template: {$this->template}");
}

throw new InvalidConfigException("Unknown template: {$this->template}");
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/console/GenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public function getActionHelpSummary($action)
{
if ($action instanceof InlineAction) {
return parent::getActionHelpSummary($action);
} else {
/** @var $action GenerateAction */
return $action->generator->getName();
}

/** @var $action GenerateAction */
return $action->generator->getName();
}

/**
Expand All @@ -156,11 +156,12 @@ public function getActionHelp($action)
{
if ($action instanceof InlineAction) {
return parent::getActionHelp($action);
} else {
/** @var $action GenerateAction */
$description = $action->generator->getDescription();
return wordwrap(preg_replace('/\s+/', ' ', $description));
}

/** @var $action GenerateAction */
$description = $action->generator->getDescription();

return wordwrap(preg_replace('/\s+/', ' ', $description));
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ public function actionPreview($id, $file)
$content = $f->preview();
if ($content !== false) {
return '<div class="content">' . $content . '</div>';
} else {
return '<div class="error">Preview is not available for this file type.</div>';
}
return '<div class="error">Preview is not available for this file type.</div>';
}
}
}
Expand Down Expand Up @@ -120,9 +119,8 @@ public function actionAction($id, $name)
$method = 'action' . $name;
if (method_exists($generator, $method)) {
return $generator->$method();
} else {
throw new NotFoundHttpException("Unknown generator action: $name");
}
throw new NotFoundHttpException("Unknown generator action: $name");
}

/**
Expand All @@ -139,8 +137,7 @@ protected function loadGenerator($id)
$this->generator->load(Yii::$app->request->post());

return $this->generator;
} else {
throw new NotFoundHttpException("Code generator not found: $id");
}
throw new NotFoundHttpException("Code generator not found: $id");
}
}
6 changes: 4 additions & 2 deletions src/generators/crud/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public function generateSearchRules()
$types = [];
foreach ($table->columns as $column) {
switch ($column->type) {
case Schema::TYPE_TINYINT:
case Schema::TYPE_SMALLINT:
case Schema::TYPE_INTEGER:
case Schema::TYPE_BIGINT:
Expand Down Expand Up @@ -428,6 +429,7 @@ public function generateSearchConditions()
$hashConditions = [];
foreach ($columns as $column => $type) {
switch ($type) {
case Schema::TYPE_TINYINT:
case Schema::TYPE_SMALLINT:
case Schema::TYPE_INTEGER:
case Schema::TYPE_BIGINT:
Expand Down Expand Up @@ -546,9 +548,9 @@ public function getTableSchema()
$class = $this->modelClass;
if (is_subclass_of($class, 'yii\db\ActiveRecord')) {
return $class::getTableSchema();
} else {
return false;
}

return false;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/generators/crud/default/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

namespace <?= StringHelper::dirname(ltrim($generator->searchModelClass, '\\')) ?>;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use <?= ltrim($generator->modelClass, '\\') . (isset($modelAlias) ? " as $modelAlias" : "") ?>;
Expand Down
1 change: 1 addition & 0 deletions src/generators/crud/default/views/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$this->title = $model-><?= $generator->getNameAttribute() ?>;
$this->params['breadcrumbs'][] = ['label' => <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-view">

Expand Down

0 comments on commit 9a9049e

Please sign in to comment.