We are very pleased to announce the release of Yii Framework version 2.0.10. Please refer to the instructions at http://www.yiiframework.com/download/ to install or upgrade to this version.
Version 2.0.10 is a minor release of Yii 2.0 which contains more than 80 enhancements and bug fixes.
There are four minor changes that may affect your existing applications so check the UPGRADE.md file.
We want to thank our excellent community which provided us great pull requests and discussions. The release wouldn't be possible without 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. There is also a forum thread about this news announcement.
Below we summarize some of most important features/fixes included in this release. A complete list of changes can be found in the CHANGELOG.
URLs ¶
yii\web\UrlNormalizer
was introduced allowing normalizing requests with and without trailing slashes which is very important
for SEO. Check out the new "URL normalization" section in the guide for details.
Migrations ¶
Migrations got some fixes as well as significant improvement. With this new release you're able to run migrations from
several locations by enabling namespaced migrations. In order to enable this feature you should configure the $migrationNamespaces
property for the controller at console application configuration:
return [
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationNamespaces' => [
'app\migrations',
'some\extension\migrations',
],
//'migrationPath' => null, // allows to disable not namespaced migration completely
],
],
];
Error handling ¶
Session errors are no longer silenced in debug mode allowing catching all the issues while in development.
Request ¶
There's now a handy method yii\web\Request::getHostName()
that returns hostname of current request so you don't
have to do it manually anymore.
Non-post requests with multipart/form-data
such as file uploads could now be parsed using yii\web\MultipartFormDataParser
.
In order to use it you should configure Request::parsers
in the following way:
return [
'components' => [
'request' => [
'parsers' => [
'multipart/form-data' => 'yii\web\MultipartFormDataParser'
],
],
// ...
],
// ...
];
And then call Request::getBodyParams()
before accessing $_FILES
.
Databases ¶
A new ActiveRecord behavior was added. yii\behaviors\AttributeTypecastBehavior
provides an ability of automatic model attribute typecasting allowing to maintain strict attribute types.
You should specify exact attribute types via attributeTypes
:
use yii\behaviors\AttributeTypecastBehavior;
class Item extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'typecast' => [
'class' => AttributeTypecastBehavior::className(),
'attributeTypes' => [
'amount' => AttributeTypecastBehavior::TYPE_INTEGER,
'price' => AttributeTypecastBehavior::TYPE_FLOAT,
'is_active' => AttributeTypecastBehavior::TYPE_BOOLEAN,
],
'typecastAfterValidate' => true,
'typecastBeforeSave' => false,
'typecastAfterFind' => false,
],
];
}
// ...
}
If attributeTypes
is left blank its value will be detected automatically based on owner validation rules:
use yii\behaviors\AttributeTypecastBehavior;
class Item extends \yii\db\ActiveRecord
{
public function rules()
{
return [
['amount', 'integer'],
['price', 'number'],
['is_active', 'boolean'],
];
}
public function behaviors()
{
return [
'typecast' => [
'class' => AttributeTypecastBehavior::className(),
'owner' => $this,
// 'attributeTypes' will be composed automatically according to `rules()`
],
];
}
// ...
}
If you use Oracle, there's now a yii\mutex\OracleMutex
which implements mutex "lock" mechanism via Oracle locks.
Console ¶
Console commands could now be invoked with -h
or --help
to display help information.
Testing ¶
Due to changes in Codeception, application templates were adjusted to reflect them. Read brand new Yii 2.0 quickstart guide at Codeception website. If you're using advanced application, refer to its testing docs.