Yii 2.0.11 is released

Feb 1, 2017

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

Version 2.0.11 is a minor release of Yii 2.0 which contains more than 110 enhancements and bug fixes.

There are four minor changes that may affect your existing applications so make sure to check the UPGRADE.md file.

Huge thanks to our excellent community. We did it together!

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. There is also a forum thread about this news announcement.

Since there's Yii 2.1 in development, make sure you have ~2.0.11 in your composer.json instead of >= or * so when next major version of Yii is released, your project won't break by itself.

Below we summarize some of most important features/fixes included in this release. A complete list of changes can be found in the CHANGELOG.

Test coverage

We've decided not to accept pull requests without unit tests with rare exceptions. That should result in better code quality and less time spent on code reviews. More than a half of 2.0.11 PRs merged were done according to this new rule.

Some tests were refactored significantly such as the ones for URL manager. Test methods got smaller and more comprehensible.

Alexey Rogachev did a really great job revising JavaScript part of the framework and adding tests for it fixing bugs found along the way. JavaScript is now well-covered by tests thanks to him so expect even more framework stability.

Console

Console got Bash and Zsh completion support for the ./yii command. It's described in the guide how to set it up.

Another usability enhancement is that the console script is now suggesting alternatives when a command isn't found because of typo.

Cache

You can now specify global default duration via yii\caching\Cache::$defaultDuration for the cache to be able to change it in a single place.

There's a new handy shortcut for typical data caching now:

$data = $cache->getOrSet($key, function () {
    return $this->calculateSomething();
});

which is the same as:

$data = $cache->get($key);
if ($data === false) {
    $data = $this->calculateSomething();
    $cache->set($key, $data);
}

Configuration

After lots of discussion, we've decided to introduce ability to set up dependencies container via application configuration:

$config = [
    'id' => 'basic',
    // ...
    'container' => [
        'definitions' => [
            'yii\widgets\LinkPager' => ['maxButtonCount' => 5]
        ],
        'singletons' => [
        ],
    ],
];

Refer to the "application configurations" section in the official guide for more information on the topic.

Usability and shortcuts

With each release we're trying to improve usability of error messages since it makes the whole development experience more comfortable. This release is not an exception. An error when you're trying to call a component which does not exist is now very clear about what happens. Previously it was giving vague hints telling you that autoloading failed.

Controller class got two new shortcut methods asJson() and asXml() for returning JSON and XML data respectively. This was possible before, but these methods adds syntactic sugar for making the common case much simpler.

Performance

In this release Yii got some performance enhancements.

  • Database is no longer issuing queries with 0=1 conditions when dealing with empty relations.
  • RBAC skips recursive checking when role assignments are empty.
  • Unique validator selects primary keys only.

Another enhancement is not exactly immediate performance enhancement but is helpful for that. We've started logging memory usage and routing data so expect new panels in debug module in next releases.

Databases

Three new methods were added to yii\db\Query: filterHaving(), andFilterHaving() and orFilterHaving(). They are alike other filter* methods which add condition only if the value passed to them is not empty. These methods are typically used in models backing up filter forms.

yii\db\Connection got multiple enhancements which may be especially useful if you are dealing with master-slave setups:

  • Added shuffleMasters option which adds ability to disable shuffling of masters connections.
  • Added getMaster() getter and master property for getting currently active master connection.

\yii\db\Query can now be passed to insert() method of database command both as 2nd argument directly and as parameter value:

$db = Yii::$app->db;
 
// insert query
 
$sourceQuery = new \yii\db\Query()
    ->select([
        'title',
        'content',
    ])->from('{{post_queue}}');
 
$command = $db->createCommand();
$command->insert('{{post}}', $sourceQuery);
 
// use query as value
 
$titleQuery = new \yii\db\Query()
    ->select('title')->from('{{titles}}')->limit(1);
 
$command = $db->createCommand();
$command->insert('{{post}}', [
    'title' => $titleQuery,
    'content' => 'Hello!',
]);

PHP 7 compatibility

With each release we're making sure everything works with latest stable releases of PHP 7.0 and PHP 7.1. In 2.0.11 we have found a single issue regarding error handler and Throwable usage which is now fixed.

URL manager

When generating URLs with UrlManager::createAbsoluteUrl(), Url::to() or Url::toRoute(), specifying schema as empty string now generates protocol relative URLs:

echo Url::to('@web/images/logo.gif', '');
// will print //www.example.com/images/logo.gif

Also Url Rules now work with protocol relative URL which makes URL handling easier with applications that support HTTP and HTTPs.

Also, when creating URLs, empty default parameters are not required anymore:

echo Url::to(['post/index', 'page' => 1, 'tag' => '']);
 
// now could be:
 
echo Url::to(['post/index', 'page' => 1]);

Widgets

Extensibility of widgets was improved significantly by adding events firing at init and before/after rendering. See issue description to find out some examples of how it may get in handy.

Security

There's now a PHP solution to host header attack. Ideally it should be solved by configuring web server properly but since it was requested and it seems to be quite common problem on shared hosts, we've added such ability to HostControl filter. You can read about configuring it in the guide.

There was an issue with request data escaping in debug mode exception screen. Since it affects only development mode and not production mode, we've decided not to make a separate release fixing it.

Composer Installer

With this release we also roll out a new version (2.0.5) of the Yii 2 Composer Installer. For those who do not know, this composer plugin is responsible for keeping track of all installed extensions and provides the configuration-less bootstrap mechanism. It also adds some hooks for running tasks when a new project is created with composer. Thanks to Robert Korulczyk, with this release it is also possible to run tasks after composer install. This is especially useful for handling local configuration files, which is now possible with the new copyFiles method. Check out the README for more information.

Since this release the plugin will also be more visible than before, as it is now notifying you about the latest notes from the UPGRADE.md file whenever you upgrade the yiisoft/yii2 package.

Signed commits and tags

This is the first release that has a GPG signed tag, so you can verify the code was published by the Yii team. We will explore this feature further in the future and also publish detailed instructions on how you can verify the code you get later.

You can already see this in form of a small "verified" tag on github: https://github.com/yiisoft/yii2-framework/releases/tag/2.0.11.