Version 2.0.6 is a patch release of Yii 2.0 which contains over 70 minor new features and bug fixes as well as numerous improvements to documentation and great progress on guide translations.
You may follow the development progress of Yii 2 by starring or watching Yii 2.0 GitHub Project. You may also follow Yii Twitter feeds or join Yii Facebook group to connect with other Yii developers.
You may follow the development progress of Yii 2 by starring or watching Yii 2.0 GitHub Project. You may also follow Yii Twitter feeds or join Yii Facebook group to connect with other Yii developers.
Better migrations syntax
$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(),
]);
This new Migration syntax is mostly useful for writing database agnostic migrations. The traditional syntax of course still works.
Error handling
In this release there are many fixes and improvements that should make error reporting and displaying errors even more reliable and useful:
- Yii is now able to properly handle HHVM fatal errors.
- A warning is now written to logs in case
FileCachefails to write into a file. yii\web\ErrorActiondisplays 404 error instead of blank page on direct access.Json::encode()andJson::decode()are handling errors better throwing meaningful exceptions.ErrorHandler::logException()now logs the whole exception object instead of only its string representation. This can be used in custom log targets to provide more detailed error information.
More control over ActiveForm using JavaScript
There's now more control over ActiveForm using JavaScript.
You can update error messages of certain fields:
// add error
$('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', ["I have an error..."]);
// remove error
$('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', '');
Or update the whole form and, optionally, summary at once:
$('#contact-form').yiiActiveForm('updateMessages', {
'contactform-subject': ['Really?'],
'contactform-email': ['I don\'t like it!']
}, true);
yii message command improvements
Message extraction command is now supports
.pot file creation.
It's now also OK with nested
Yii::t() calls such as the following:Yii::t('app', 'There are new {messages} for you!', [
'messages' => Html::a(Yii::t('app', 'messages'), ['user/notifications']),
]);
It's always sorting created messages, even if there is no new one, while saving to PHP files. It allows you to have much smaller diff.
There's new config option called
markUnused that allows configuring behaviour of adding @@ to unused messages.Assets
It's now possible to fine-tune what's published and what's 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 now customize the way directory name hashes (the ones in
web/assets directory) are generated. It could be done right from application config:return [
// ...
'components' => [
'assetManager' => [
'hashCallback' => function ($path) {
return hash('md4', $path);
}
],
],
];
Extra session fields
You can now easily store extra data in session storage. Currently it's supported in
yii\web\DbSession but could be possibly extended to more storages in future. In order to configure it, modify the session component in your application config: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),
];
}
],
],
];
