📜 ⬆️ ⬇️

Yii 2.0.8

Release PHP-framework version 2.0.8 Yii. Instructions for upgrading and installing can be found on page
http://www.yiiframework.com/download/ .


Version 2.0.8 contains about 100 minor fixes and improvements , has 300 commits, from 64 authors and affects 150 files.


Upgrading may require additional steps, so it is worth referring to UPGRADE.md .


Thanks to our great community for great ideas and pull requests. This release was made thanks to you!


The framework development process can be monitored on GitHub . Also subscribe to our Twitter and join the group on Facebook .


Below we look at the most interesting changes to this release. A complete list of changes can be found in CHANGELOG .


PHP 7 compatibility


Yii 2.0.8 received a couple of fixes on this topic. One concerns error handling in general, the second is handling JSON errors.


As you most likely already know, PHP 7 will become quite common this year because this version is available in the latest Ubuntu LTS package.


Databases and ActiveRecord


The method for filtering the provider for a GridView from Yii 1.1 appeared in Yii 2.0 as yii\db\Query::andFilterCompare() .


Documentation has not ripened . We will be glad to help in its writing.


In ActiveRecord, they now call EVENT_AFTER_REFRESH after the model updates its data from the database.


Scheme and Migration


Thanks to the community, this release includes improvements to the database schema builder, which is usually used in migrations.


First, it is now possible to add comments to tables and columns. When defining a column, this is done like this:


 'title' => $this->string()->notNull()->comment('Hello, I am the title!'), 

Separate methods can be used like this:


 $this->addCommentOnTable('user', 'This is a table comment.'); $this->addCommentOnColumn('user', 'name', 'This is a column comment.'); $this->dropCommentFromColumn('user', 'name'); $this->dropCommentFromTable('user'); 

It became possible to set the order of the created column:


 $this->string()->notNull()->first(); $this->string()->notNull()->after('anotherColumn'); 

Now declaring unsigned primary keys is much nicer: $this->primaryKey()->unsigned() .


The console command ./yii migrate/create also been slightly improved. First, the useTablePrefix option useTablePrefix . If it is set to true , the code with table prefixes will be generated.


Secondly, you can generate foreign keys via --fields :


 yii migrate/create create_post --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text" 

Forms and Validation


Have you ever forgotten to ask the form the necessary enctype to download files? No more forgetting. Yii will add it automatically if fileInput is used in the Active Form.


In the validation rules, it is now possible to make a field validated, but at the same time inaccessible for mass assignment by adding an exclamation mark to the beginning of its name .


When using FileValidator, you can set mimeTypes using the wildcard pattern. For example, image/* will mean all types starting with image/ ( image/jpeg , image/png , etc.).


DateValidator has learned to validate even more time formats. Now you can set the $ type property to TYPE_DATETIME or TYPE_TIME to validate short intl formats.


Security


Thanks to Tom Worster's research and the productive discussions that followed, Security was able to improve:



The changes are not critical, so upgrading to 2.0.8 at breakneck is not necessary.


Component tests have also been reworked, so coverage on different systems with different extensions available is now much better.


Console commands


In addition to the existing options, now for most of the options you can use short alias flags. For example, when creating migrations you can use


 ./yii migrate/create -p=@app/modules/somemodule/migrations -t=module_migrations new_migration 

instead


 ./yii migrate/create --migrationPath=@app/modules/somemodule/migrations --migrationTable=module_migrations new_migration 

In your own controllers you can implement this by overriding the method yii\console\Controller::optionAliases() .


Introducing dependencies into anonymous functions in configs


Dependencies are now automatically embedded in the closures used in the configuration:


  'components' => [ 'pheanstalk' => function(yii\web\User $user) { $result = new \Pheanstalk\Pheanstalk('localhost'); $result->watch($user->getId()); return $result; }, // ... 

PostgreSQL mutex


There was a Mutex implementation under PostgreSQL. If you use this DBMS, you have another option for locking.


Advanced project template


A configuration for vagrant appeared in the advanced project template, which allows you to quickly raise the working environment.
More information about it can be found in the documentation .


')

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


All Articles