📜 ⬆️ ⬇️

Yii 2.0.10

A new version of the PHP framework Yii has been released, including more than 80 improvements and bug fixes . Installation and upgrade instructions can be found at . It is worth noting that the release includes four small changes that may affect the operation of existing applications. Be sure to read UPGRADE.md .


Thanks to the great community for great pull requests and discussions. Without you, this release would not exist! You can begin to follow the development process of Yii 2 by putting an asterisk on GitHub . Subscribe to our Twitter and Facebook . You can discuss the release in the comments.


A complete list of changes can be found in CHANGELOG . Next we look at the most interesting.


URL


The new class yii\web\UrlNormalizer allows yii\web\UrlNormalizer to normalize requests for URIs with a slash present or missing at the end, which is quite important for search engine optimization. A detailed description can be found in the " URL normalization " section of the official manual.


Migrations


In addition to minor fixes, migrations also received quite a significant improvement. Now you can run migrations from several places at the same time, if you use namespaces for them. To do this, you need to set the consoleName's migrationNamespaces property:


 return [ 'controllerMap' => [ 'migrate' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationNamespaces' => [ 'app\migrations', 'some\extension\migrations', ], //'migrationPath' => null, //      ], ], ]; 

Error processing


Errors when writing and reading a session are no longer hidden in debug mode, which makes it easy to identify most of the problems at the design stage.


Request


A new method, yii\web\Request::getHostName() , returns the host name for the current request.


Non-POST requests encoded as multipart/form-data (for example, file yii\web\MultipartFormDataParser ) can now be yii\web\MultipartFormDataParser via yii\web\MultipartFormDataParser . In order to use this, you must configure Request::parsers as follows:


 return [ 'components' => [ 'request' => [ 'parsers' => [ 'multipart/form-data' => 'yii\web\MultipartFormDataParser' ], ], // ... ], // ... ]; 

After that, call Request::getBodyParams() and the request will be parsed into the corresponding variables. Including $_FILES .


Database


A new behavior has been added for ActiveRecord. yii\behaviors\AttributeTypecastBehavior allows you to automatically bring types of attribute values.


Types are set via attributeTypes :


 use yii\behaviors\AttributeTypecastBehavior; class Item extends \yii\db\ActiveRecord { public function behaviors() { return [ 'typecast' => [ 'class' => AttributeTypecastBehavior::className(), 'attributeTypes' => [ 'amount' => AttributeTypecastBehavior::TYPE_INTEGER, 'price' => AttributeTypecastBehavior::TYPE_FLOAT, 'is_active' => AttributeTypecastBehavior::TYPE_BOOLEAN, ], 'typecastAfterValidate' => true, 'typecastBeforeSave' => false, 'typecastAfterFind' => false, ], ]; } // ... } 

If attributeTypes not specified, the value will be determined automatically based on validation rules:


 use yii\behaviors\AttributeTypecastBehavior; class Item extends \yii\db\ActiveRecord { public function rules() { return [ ['amount', 'integer'], ['price', 'number'], ['is_active', 'boolean'], ]; } public function behaviors() { return [ 'typecast' => [ 'class' => AttributeTypecastBehavior::className(), 'owner' => $this, // 'attributeTypes'      `rules()` ], ]; } // ... } 

Also added was yii\mutex\OracleMutex - an implementation of blocking capabilities with Oracle.


Console


In the console, you can now call the description of the command by passing -h or --help .


Testing


Application templates have been modified to work with recent changes to Codeception. Read more about this in the new section on the Codeception website: " Yii 2.0 quickstart guide ". If you use the advanced project template, check out its test documentation .


')

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


All Articles