Yii 2.0.7

    Version 2.0.7 of the Yii PHP framework has been released. How to install or upgrade is described at http://www.yiiframework.com/download/ .

    This version contains more than a hundred improvements and corrections , clarification of documentation and its translations.

    To update, you may need to perform additional steps described in UPGRADE.md .

    Thanks to our wonderful community , which has given us a lot of pull requests and discussions. Without you, this release would not have happened. Thanks!

    You can follow the Yii development process by putting an asterisk or clicking on watch on the project page on GitHub . We also have Twitter and a Facebook group..

    Well, now we will consider the most interesting improvements and corrections of this release.

    IP Validator



    The new validator can check IP for clear correspondence, ranges and masks. It can be used as a separate validator, or as part of a rules()model method :

    public function rules()
    {
        return [
            ['address', 'ip', 'ranges' => [
                 '192.168.10.128'
                 '!192.168.10.0/24',
                 'any' // все остальные адреса
            ]],
        ];
    }
    


    The validator features are described in more detail in the manual , class comments, and
    tests .

    i18n



    The formatter has acquired a new method asDuration()that allows you to get a readable string from the time interval represented by the DateInterval object , the number of seconds or the ISO8601 string :

    echo Yii::$app->formatter->asDuration(131);
    // выведет "2 minutes, 11 seconds"
    


    Now yii\i18n\Formatter::$calendaryou can choose through which calendar to format dates. For example, you can use the Persian calendar like this:

    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');
    // выведет "۱۳۹۴"
    


    A detailed description can be found in the class documentation .

    In addition, transliteration outside the context of the URL is now available as Inflector::transliterate(), which is useful for generating keywords and other metadata when developing for languages ​​such as Vietnamese.

    Database



    In addition to corrections, several interesting improvements were included in the release. In Query::groupBy()and Query::orderBy()now you can use yii\db\Expression:

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


    For SQLite, the use of aliases in DSN has become possible:

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


    For JOINs with related records, Active Record has a simplified way to name tables. The syntax available earlier in join()can now be used in joinWith():

    // join-им с заказами и сортируем результат по orders.id
    $query->joinWith(['orders o'])->orderBy('o.id');
    


    Improvements to the new migration syntax



    The new migration syntax introduced in 2.0.6 received several improvements. Firstly, this is support unsigned:

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


    Secondly, you can now use expressions as default values:

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


    Console Migration Generator



    The team ./yii migrate/createhas become smarter. Based on the name of the created migration and parameters, she learned how to generate the migration code:

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


    will 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');
        }
    }
    


    The syntax is described in detail in the manual . We hope the innovation saves your time.

    RBAC Interface Extension



    A method has been added to the RBAC interface getUserIdsByRole(). It will certainly be useful when developing an admin panel for roles and permissions.

    Error handling and output



    • Added support for PHP 5.5 error codes when processing JSON. This allows you to accurately determine the reason why the encoding in JSON failed.
    • VarDumper::dump()learned to work with the magic method of PHP __debugInfo().
    • The error handler for safety reasons, no longer shows $_ENVand $_SERVERon the error page. The displayed data is configured through yii\web\ErrorHandler::$displayVars.
    • yii\helpers\VarDumper::export() learned to work with circular links, which makes logging and the debugging panel more reliable.

    Also popular now: