📜 ⬆️ ⬇️

Yii 2.0.3

The release of the PHP framework Yii version 2.0.3 was released on time. The order of updating and installation is described at http://www.yiiframework.com/download/ .

This version includes about 50 improvements and fixes. A complete list can be viewed on GitHub . Taking this opportunity, the team is grateful to everyone who helps us .

Special thanks to those who improve the documentation and translate it into many languages.
')
It is convenient to follow the development process of the framework on GitHub by setting the project an asterisk or using the watch button. Subscribe to our Twitter and Facebook .

Below we consider the most important improvements of this version.



Cryptography



This is a rather serious change, albeit an internal one. For yii\base\Security we replaced Mcrypt (which has been abandoned for eight years now) with OpenSSL, for which we should say thanks to Tom Worster, who is watching Yii for security. Since OpenSSL is present by default in most PHP distributions, compatibility problems should not arise. But, if they do, be sure to inform.

RBAC caching



If you store RBAC data in a database, you may have noticed that the performance is not perfect: each check results in quite a significant amount of SQL queries. To fix this, we added caching to yii\rbac\DbManager . The entire hierarchy is cached, which greatly increases the performance of checkAccess() . RBAC caching is disabled by default. Included as follows:

 return [ 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\DbManager', 'cache' => 'cache', // <----   ], 'cache' => [ 'class' => 'yii\caching\ApcCache', ] // ... ], ] 


Page caching



Previously, page caching was limited to HTML. It did not work for the REST API due to incorrect HTTP headers. Now you can use yii\filters\PageCache to cache various types of data and headers. This is how you can cache the index action of the REST controller:

 public function behaviors() { return [ [ 'class' => 'yii\filters\PageCache', 'only' => ['index'], 'duration' => 60, ], ]; } 


Forced download of fresh resources



Another caching enhancement is support for pushing fresh resources, which is often useful on production servers when HTTP caching of JS or CSS files is enabled. In this case, even if you make changes to the resource files, the client can get the old version from the cache. Now you can set the yii\web\AssetManager::appendTimestamp to true. The file modification time will be added to the URL of the JS and CSS resources, so the client will always receive the latest version:

 return [ 'components' => [ 'assetManager' => [ 'class' => 'yii\web\AssetManager', 'appendTimestamp' => true, ], // ... ], ] 


Current URL Changes



A new method, yii\helpers\Url::current() , has been added, which makes it easier to change the current URL by adding or removing GET parameters:

 // , $_GET = ['id' => 123, 'src' => 'google'],   "post/view" // /index.php?r=post/view&id=123&src=google echo Url::current(); // /index.php?r=post/view&id=123 echo Url::current(['src' => null]); // /index.php?r=post/view&id=100&src=google echo Url::current(['id' => 100]); 


Turn off log rotation



If you write logs to files via yii\log\FileTarget , you can now turn off automatic file rotation, which is useful if additional utilities do this:

 return [ 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'enableRotation' => false, ], ], ], ], ]; 


Data attributes



When using yii\helpers\Html the data attribute is handled in a special way:

 // : <div data-name="xyz" data-age="20"></div> echo Html::tag('div', '', ['data' => ['name' => 'xyz', 'age' => 20]]); 


Now ng and data-ng are also processed. This is useful primarily for those working with AngularJS. For the remaining attributes, the array will be converted to JSON.

You can specify which attributes to process in a special way by adding them to yii\helpers\Html::$dataAttributes .

Trimming Input



If you use the trim validation rule, you will find that trimming is now done on the client. You can disable this behavior by setting the enableClientValidation property of the trim validation rule to false.

Maximum field length



When using yii\helpers\Html::activeTextInput() or yii\widgets\ActiveField::textInput() , you may need to set the maxlength property to create input fields. If the corresponding model field has a string validation rule, maxlength can be taken from it. For this maxlength you must specify the value true:

 //  "name"   : ['name', 'string', 'max' => 128] // generates: <input type="text" ... maxlength="128"> echo Html::activeTextInput($model, 'name', ['maxlength' => true]); 


Configurable objects



Now you can use the new yii\base\Configurable interface to mark the class as “configurable”. In this case, yii\di\Container expects the constructor to accept the configuration array:

 class Foo implements \yii\base\Configurable { public function __construct($a, $b, $config = []) { } } $container = new \yii\di\Container; $object = $container->get('Foo', [1, 2], ['prop1' => 3]); // : $object = new Foo(1, 2, ['prop1' => 3]); 


Previously, it was necessary to inherit from yii\base\Object to achieve a similar effect.

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


All Articles