📜 ⬆️ ⬇️

Yii 2.0.6

The PHP framework Yii version 2.0.6 has been released.

Installation and upgrade instructions are available at http://www.yiiframework.com/download/ .

Version 2.0.6 is a patch release for branch 2.0 and contains more than 70 minor improvements and fixes , numerous documentation improvements and significant progress with its translation.
')
Thanks to everyone who participates in the development of the framework . Your pull requests, discussions and other help are irreplaceable.

You can follow the development process of the framework by placing an asterisk or by clicking the “watch” button on GitHub .
You can also subscribe to our Twitter and Facebook .

Below is a brief overview of the most interesting innovations.



Improved migration syntax



Initially we planned the schema builder in version 2.1, but pana1990 and vaseninm did a great job and now the syntax in the migrations has become much more pleasant:

$this->createTable('example_table', [ 'id' => $this->primaryKey(), 'name' => $this->string(64)->notNull(), 'type' => $this->integer()->notNull()->defaultValue(10), 'description' => $this->text(), 'rule_name' => $this->string(64), 'data' => $this->text(), 'created_at' => $this->datetime()->notNull(), 'updated_at' => $this->datetime(), ]); 


Error processing



There are quite a few fixes and improvements in this release designed to make error handling even more stable and useful:

- Yii now copes with HHVM's fatal errors.
- If FileCache could not write to the file, it will be visible in the logs.
- yii\web\ErrorAction now shows 404, not a blank page in the case of a direct URL.
- When yii migrate refuses to work because of a missing directory, the path to it is shown in error.
- Json::encode() and Json::decode() better handle errors, throwing clear exceptions.
- ErrorHandler::logException() now logs the entire object, not just its string representation.

More control over ActiveForm from JavaScript



You can update errors for specific fields:

 //   $('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', ["I have an error..."]); //   $('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', ''); 

Or for all fields and resumes at once:


 $('#contact-form').yiiActiveForm('updateMessages', { 'contactform-subject': ['Really?'], 'contactform-email': ['I don\'t like it!'] }, true); 


yii message enhancements



Now the creation of .pot files is .pot .

The command now perfectly digests nested calls:

 Yii::t('app', 'There are new {messages} for you!', [ 'messages' => Html::a(Yii::t('app', 'messages'), ['user/notifications']), ]); 


Also now sorting occurs even in the absence of new lines, which allows to get a smaller diff.

In addition, the markUnused option was added, which allows you to disable adding @@ to unused strings.

Assets



Now you can configure what to publish and what not:

 class MyAsset extends AssetBundle { public $sourcePath = '@app/assets/js'; public $js = [ 'app.js', ]; public $depends = [ 'yii\web\YiiAsset', ]; public $publishOptions = [ 'except' => '*.ts', // exclude TypeScript sources // 'only' => '*.js', // include JavaScript only ]; } 


You can change the hashing algorithm for directory names from web/assets . This can be done directly from the application configuration:

 return [ // ... 'components' => [ 'assetManager' => [ 'hashCallback' => function ($path) { return hash('md4', $path); } ], ], ]; 


Additional fields in the session repository



Now you can easily store additional data in the session repository. So far, only yii\web\DbSession , but support may be extended in the future. For configuration, you need to change the configuration of the application:

 return [ // ... 'components' => [ 'session' => [ 'class' => 'yii\web\DbSession', 'readCallback' => function ($fields) { return [ 'expireDate' => Yii::$app->formatter->asDate($fields['expire']), ]; }, 'writeCallback' => function ($session) { return [ 'user_id' => Yii::$app->user->id, 'ip' => $_SERVER['REMOTE_ADDR'], 'is_trusted' => $session->get('is_trusted', false), ]; } ], ], ]; 

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


All Articles