📜 ⬆️ ⬇️

Yii 2.0.7

Version 2.0.7 of PHP framework Yii has been released. How to install or upgrade is described at http://www.yiiframework.com/download/ .

This version contains more than a hundred improvements and fixes , documentation clarifications and its translations.

To upgrade, you may need to perform additional steps described in UPGRADE.md .
')
Thanks to our wonderful community , which has given us a lot of pull requests and discussions. Without you, this release would not exist. Thank!

You can follow the development process of Yii by placing an asterisk or clicking on watch on the project page on GitHub . We also have Twitter and a Facebook group .

Well, now consider the most interesting improvements and fixes for this release.

IP validator



The new validator can check IP for a clear match, ranges and masks. It can be used as a separate validator, and as part of the rules() method of the model:

 public function rules() { return [ ['address', 'ip', 'ranges' => [ '192.168.10.128' '!192.168.10.0/24', 'any' //    ]], ]; } 


Details of the validator’s capabilities are described in the manual , class comments and
tests .

i18n



The formatter acquired a new method asDuration() , which allows you to get a readable string from the time interval represented by a DateInterval object , the number of seconds or the ISO8601 string :

 echo Yii::$app->formatter->asDuration(131); //  "2 minutes, 11 seconds" 


Now, using yii\i18n\Formatter::$calendar you can choose which calendar to format dates for. For example, the Persian calendar can be used like this:

 Yii::$app->formatter->locale = 'fa_IR@calendar=persian'; Yii::$app->formatter->calendar = \IntlDateFormatter::TRADITIONAL; Yii::$app->formatter->timeZone = 'UTC'; $value = 1451606400; // Fri, 01 Jan 2016 00:00:00 (UTC) echo Yii::$app->formatter->asDate($value, 'php:Y'); //  "۱۳۹۴" 


A detailed description can be found in the class documentation .

In addition, transliteration outside the context of the URL is now available as Inflector::transliterate() , which is useful for generating keywords and other metadata when developing for languages ​​such as Vietnamese.

Database



In addition to the fixes, several interesting improvements were included in the release. In Query::groupBy() and Query::orderBy() you can now use yii\db\Expression :

 $expression = new Expression('SUBSTR(name, 2)'); $users = (new \yii\db\Query) ->from('user') ->orderBy($expression) ->limit(10) ->all(); 


For SQLite, it became possible to use aliases in DSN:

 'db' => [ 'dsn' => 'sqlite:@app/db/database.sqlite3', ] 


For JOIN with related records in Active Record, there is a simplified way to name tables. The syntax available earlier in join() can now be used in joinWith() :

 // join-       orders.id $query->joinWith(['orders o'])->orderBy('o.id'); 


Improvements to the new migration syntax



The new migration syntax introduced in 2.0.6 has received several improvements. First, it is unsigned support:

 'createdBy' => $this->integer(10)->unsigned(), 


Secondly, you can now use expressions as default values:

 $this->integer()->defaultExpression('CURRENT_TIMESTAMP'); 


Console Migration Generator



The ./yii migrate/create command ./yii migrate/create become smarter. Based on the name of the migration being created and the parameters, she learned how to generate the migration code itself:

 ./yii migrate/create create_post --fields=title:string,body:text 


will generate:

 class m150811_220037_create_post extends Migration { public function up() { $this->createTable('post', [ 'id' => $this->primaryKey(), 'title' => $this->string(), 'body' => $this->text() ]); } public function down() { $this->dropTable('post'); } } 


The syntax is described in detail in the manual . We hope that innovation will save your time.

RBAC interface extension



The getUserIdsByRole() method has been added to the RBAC interface. It will certainly be useful in the development of the admin for roles and permissions.

Error handling and output



Source: https://habr.com/ru/post/277201/


All Articles