Yii 2.0.7 is released

Feb 14, 2016

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

Version 2.0.7 is a patch release of Yii 2.0 which contains over 100 minor new features and bug fixes as well as numerous improvements to documentation and guide translations.

There are extra steps to do while upgrading so check the UPGRADE.md file.

Thanks to our awesome Yii community we've got valuable pull requests and discussions that made this release possible. 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/fixes included in this release.

IP validator

There's now new validator for IP addreesses, ranges and masks. It could be used either as standalone validator or as a part of model's rules() method:

public function rules()
{
    return [
        ['address', 'ip', 'ranges' => [
             '192.168.10.128'
             '!192.168.10.0/24',
             'any' // allows any other IP addresses
        ]],
    ];
}

You can get an idea of what's capable of by looking at the paragraph of the guide, class comments or tests.

i18n

Formatter got a new asDuration() method for getting a human readable string from an interval presented by either DateInterval object, number of seconds or ISO8601 string:

echo Yii::$app->formatter->asDuration(131);
// outputs "2 minutes, 11 seconds"

Another enhancement is an ability to choose the calendar that would be used for date formatting. You can do so by setting the yii\i18n\Formatter::$calendar property. The following is an example of using Persian calendar:

Yii::$app->formatter->locale = 'fa_IR@calendar=persian';
Yii::$app->formatter->calendar = \IntlDateFormatter::TRADITIONAL;
Yii::$app->formatter->timeZone = 'UTC';
$value = 1451606400; // Fri, 01 Jan 2016 00:00:00 (UTC)
echo Yii::$app->formatter->asDate($value, 'php:Y');
// outputs "۱۳۹۴"

Check class documentation for details.

Besides that, non-URL specific transliteration is now exposed as Inflector::transliterate() which is useful for generating keywords and other metadata for languages such as Vietnamese.

Database

Besides fixes there are some notable enhancements. You can now use yii\db\Expression in Query::groupBy() and Query::orderBy():

$expression = new Expression('SUBSTR(name, 2)');
$users = (new \yii\db\Query)
    ->from('user')
    ->orderBy($expression)
    ->limit(10)
    ->all();

For SQLite you can now use aliases in DSN:

'db' => [
    'dsn' => 'sqlite:@app/db/database.sqlite3',
]

For joining with relations in active record a simpler way for specifying a table alias has been added. One can now use a similar syntax as with join() also in joinWith():

// join the orders relation and sort the result by orders.id
$query->joinWith(['orders o'])->orderBy('o.id');

Enhancements to new migration syntax

New migrations syntax introduced in 2.0.6 got some enhancements. First of all, that's unsigned support:

'createdBy' => $this->integer(10)->unsigned(),

Second, you can now use expression as default value:

$this->integer()->defaultExpression('CURRENT_TIMESTAMP');

Console migration generator

./yii migrate/create got smarter. Based on migration name it can now generate boilerplate code for migration so you don't have to type that much:

./yii migrate/create create_post --fields=title:string,body:text

would generate:

class m150811_220037_create_post extends Migration
{
    public function up()
    {
        $this->createTable('post', [
            'id' => $this->primaryKey(),
            'title' => $this->string(),
            'body' => $this->text()
        ]);
    }
 
    public function down()
    {
        $this->dropTable('post');
    }
}

Check the guide to learn the syntax. We hope it would save you even more time.

RBAC interface expansion

RBAC interface was extended with getUserIdsByRole() method which should come in handy when implementing your own UI to manage roles and permissions.

Error handling and dumping

  • Yii got improved JSON error handling to support PHP 5.5 error codes which is really helpful to determine why encoding failed.
  • VarDumper::dump() now respects __debugInfo() PHP magic method.
  • Error handler now doesn't display $_ENV and $_SERVER at error page by default for the security reasons. What's displayed could be customized by yii\web\ErrorHandler::$displayVars.
  • yii\helpers\VarDumper::export() is now able to export circle referenced objects which makes logging and debug toolbar much more reliable.

Security

We're constantly monitoring and checking the best ways to get truly random values and deal with passwords and evolving accordingly. Now Security component uses random_bytes(), LibreSSL, mcrypt, limits OpenSSL usage to Windows and prefers password_hash() over crypt().

PHP 7

ApcCache is now able to handle PHP 7 APCu properly. In order to use it set useApcu cache property to true.

Built-in webserver

You're now able to develop Yii 2.0 apps without installing full featured web server such as nginx or Apache, by typing ./yii serve in console and opening your browser at http://localhost:8080. Hostname and port could be specified via extra parameters type ./yii help serve for syntax details.

PJAX

PJAX experience overall should be significantly better. There are fixes for data-methods, redirects, loading scripts that present in PJAX response and more.

Validation

  • Client validation now skips disabled inputs.
  • "compare" validator got improved error messages.
  • There's now ability to specify range for in validator using anonymous function.
  • File validator now could have maxFiles set to 0 to allow unlimited number of files.

Events

Events are now respecting inheritance and could be attached to the whole class/interface hierarchy. See guide for details.

Assets

It's now possible to specify CSS and JavaScript options per file in an asset bundle class:

public $css = [
    'default_options.css',
    ['tv.css', 'media' => 'tv'],
    ['screen_and_print.css', 'media' => 'screen, print']
];
 
public $js = [
    'normal.js',
    ['defered.js', 'defer' => true],
];

REST API

For debugging purpose JsonResponseFormatter can now be configured to format the returned JSON in better readable format. You may configure the response application component in the following way:

'response' => [
    // ...
    'formatters' => [
        \yii\web\Response::FORMAT_JSON => [
             'class' => 'yii\web\JsonResponseFormatter',
             'prettyPrint' => YII_DEBUG, // use "pretty" output in debug mode
             // ...
        ],
    ],
],

Tags

release