The release of the PHP framework Yii version 2.0.13. It includes more than 90 improvements and fixes .
Please note that there are changes in the release that may affect existing applications. They are described in UPGRADE.md .
Many thanks to the Yii community for their support and pull requests!
You can follow the development process by putting an asterisk on GitHub . Also subscribe
on our twitter and facebook .
Since we are working on Yii 2.1 , make sure that the version of the framework in composer.json
spelled correctly ( ~2.0.13
) and you will not upgrade to 2.1 by accident when it is released.
Below we look at the most interesting improvements and fixes release. A complete list can be found in CHANGELOG .
Both the "basic" and "advanced" templates now use asset-packagist.org instead of the Composer asset plugin.
Vagrant environment in advanced acquired XDdebug-ohm. Also, it has become even easier to raise. Required plugins are put automatically.
The Alert
widget has been added to the "basic" template (it was already in "advanced").
Logging, debugging and error handling is what we do every day. Tools for this should work like a clock providing as much relevant information as possible. In this release on this topic, the improvements are as follows:
yii\web\DbSession
now uses the error handler's capabilities to display the exception page. As it turned out, quite often developers forgot to check objects for existence when writing additional data to the database with sessions. Debugging it was very difficult, because the errors were about the unsuccessful recording in the session. Now the real reason is shown.Among other things, Carsten Brandt improved the exception page by adding some useful buttons:
Thanks to the wonderful work of Pavel Klimov, data filters and their integration into the REST API appeared in Yii. Filters can be used to build complex conditions for data providers. They are perfectly customizable and fit like
web applications as well as REST API.
Documentation is available in the " Filtering Data Providers using Data Filters " section.
Proper behavior under concurrency is very important for high-load projects. We fixed a few bugs on this topic. @kidol corrected the processing of the race condition in yii\mutex\FileMutex
. @dynasource did the same for publishing assets to
case using symbolic links.
What has changed:
PHP 7.2 is close. RC is published and there will be a stable release soon. In 7.2 there are significant improvements, but there is also a breakdown of compatibility. Starting with this release, Yii 2 is fully compatible with PHP 7.2.
In addition to small changes, there is also a big one that can affect your applications. Beginning with PHP 7.2, the use of certain keywords in class names object
, was prohibited.
Using Object
in PHP 7.2 causes a fatal error. In Yii, there is a class yii\base\Object
, which was used as the base class for most framework classes, many extensions, and applications.
For Yii to work with PHP 7.2, we renamed the class. yii\base\Object
marked as deprecated. Use yii\base\BaseObject
. Versions Yii 2 to 2.0.13 are not compatible with PHP 7.2.
More detailed changes required for applications are described in UPGRADE .
The getOrigin()
method has been added to the yii\web\Request
class. It returns the HTTP_ORIGIN
current CORS request.
Also, a new filter yii\filters\AjaxFilter
, allowing to restrict access to the action of the AJAX controller requests.
A non-critical CVE-2017-11516 problem was found and fixed with screening in the error handler in debug mode.
Security requests increased by maintaining a list of trusted proxies . In the process, we removed the HTTP / HTTPS status via X-Forwarded-Proto
by default.
In the console, there were interesting improvements. First, the yii\console\ExitCode
, which contains constants that can be used for return codes for console commands:
if ($this->importData()) { return ExitCode::OK; } else { ExitCode::SOFTWARE; }
Secondly, it became possible to display the tables:
echo Table::widget([ 'headers' => ['test1', 'test2', 'test3'], 'rows' => [ ['col1', 'col2', 'col3'], ['col1', 'col2', ['col3-0', 'col3-1', 'col3-2']], ], ]);
will lead
βββββββββ€ββββββββ€βββββββββββ β test1 β test2 β test3 β βββββββββΌββββββββΌβββββββββββ’ β col1 β col2 β col3 β βββββββββΌββββββββΌβββββββββββ’ β col1 β col2 β β’ col3-0 β β β β β’ col3-1 β β β β β’ col3-2 β βββββββββ§ββββββββ§βββββββββββ
Sergey Makinen has implemented an API for managing constraints:
$connection = Yii::$app->db; $connection ->createCommand() ->addUnique('unique-username', 'user', 'username') ->execute(); $connection ->createCommand() ->dropUnique('unique-username', 'user') ->execute(); $connection ->createCommand() ->addCheck('check-price', 'order', 'price > 0') ->execute(); $connection ->createCommand() ->dropCheck('check-price', 'order') ->execute(); $connection ->createCommand() ->addDefaultValue('default-balance', 'account', 'balance', 0) ->execute(); $connection ->createCommand() ->dropDefaultValue('default-balance', 'account') ->execute();
You can also get various information:
/** @var Schema $schema */ $schema = $connection->getSchema(); $fks = $schema->getTableForeignKeys('user'); foreach ($fks as $fk) { echo $fk->onUpdate; }
Those interested can look at this commit .
We began to smoothly introduce interfaces for some components. This time it is yii\caching\CacheInterface
. There will be both in 2.0 and 2.1.
The new migrate/fresh
command cleans the database and re-apply all migrations.
The options $compact
(makes the output more compressed) and $maxSqlOutputLength
(cuts SQL to a specified number of characters) are added to the Migration
class.
The service module locator is available from its controllers as $this->module->get('myComponent')
. If the object cannot be retrieved from it, attempts are made to retrieve the object from the locator service of the parent module. Since the parent of all modules is an application, the component will eventually be searched for in it.
This change will make it easier to build insulated modules. When using $this->module->get('myComponent')
you automatically get the opportunity to override dependencies from the module configuration, but still rely on the application components.
Examples can be found in " Accessing components from within modules ".
A ArrayHelper
setValue()
method has been setValue()
. He writes the value to the associative array at the specified path. If there is no such path, the corresponding keys will be created. If so, the value will be overwritten. Two syntaxes are supported:
ArrayHelper::setValue($array, 'key.in', ['arr' => 'val']);
and
ArrayHelper::setValue($array, ['key', 'in'], ['arr' => 'val']);
Another method in the release is StringHelper::floatToString()
. It converts float
to string
, but, unlike native casting, it always uses dots as a separator for the whole part.
yii\rbac\DbManager::checkAccess()
stopped making extra requests when receiving appointments. If you stored a hierarchy in the database, the performance after the upgrade is likely to increase. An additional index was also added to the tables, which made the queries themselves faster.
Despite the fact that in Yii 2.1 we are trying to make the framework independent of JavaScript, 2.0 is tied to jQuery. We updated JS and PHP code for compatibility with jQuery 3.0.
A new instance($refresh = false);
method has been added to the yii\db\ActiveRecordInterface
through the new yii\base\StaticInstanceInterface
instance($refresh = false);
. Its purpose is to provide static instances of classes that can be used to obtain various
metadata not available through static methods. For example, changes made through DI or using behaviors can be made only at the object level, but, in some cases, it would be useful to make them at a static class level.
yii\behaviors\AttributesBehavior
been added. It assigns values ββto one or more attributes of the ActiveRecord object at certain events. Unlike yii\behaviors\AttributeBehavior
it works with several attributes at once. In both AttributeBehavior
and AttributesBehavior
, the preserveNonEmptyValues
option has been added. When set to true
it only allows values ββto be overwritten when they are empty.
Added option skipOnEmpty
yii\behaviors\SluggableBehavior
skipOnEmpty
. Enabling it prevents the generation of a new slug if the attribute is null
or empty.
Resource directory hashing now takes into account symbolic links. Thereby, cache invalidation was fixed in the case when resources were not updated after the transition from copying to links. Previously, you had to delete the contents of the assets directory.
The compression and assembly of resources by the console command now takes into account that many popular libraries do not install ;
at the end of the file. From this, some script combinations did not work.
Added method yii\web\View::registerCsrfMetaTags()
. It registers CSRF tags dynamically, which allows you to be sure that caching does not affect them.
The following methods have Formatter
added to the Formatter
:
asWeight()
formats the number as weight, that is, "12 kilograms".asShortWeight()
formats the number as weight in short form, i.e. "12 kg".asLength()
formats the number as a length, that is, "12 meters".asShortLength()
formats a number as a length in short form, i.e. "12 m".UPDATE: and some release extensions .
Source: https://habr.com/ru/post/341614/