Yii 2.0.6 is released

Aug 5, 2015

We are very pleased to announce the release of Yii Framework version 2.0.6. Please refer to the instructions at http://www.yiiframework.com/download/ to install or upgrade to this version.

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.

We thank our excellent Yii community who helped us with pull requests and valuable discussions. Thank you!

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.

Below we summarize some of most important features included in this release.

Better migrations syntax

We were planning schema builder for 2.1 initially but pana1990 and vaseninm took action and now we've got much 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 FileCache fails to write into a file.
  • yii\web\ErrorAction displays 404 error instead of blank page on direct access.
  • Json::encode() and Json::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.


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 = [
    public $depends = [
    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),