rules()
method of the model: public function rules() { return [ ['address', 'ip', 'ranges' => [ '192.168.10.128' '!192.168.10.0/24', 'any' // ]], ]; }
asDuration()
, which allows you to get a readable string from the time interval represented by a DateInterval object , the number of seconds or the ISO8601 string : echo Yii::$app->formatter->asDuration(131); // "2 minutes, 11 seconds"
yii\i18n\Formatter::$calendar
you can choose which calendar to format dates for. For example, the Persian calendar can be used 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'); // "۱۳۹۴"
Inflector::transliterate()
, which is useful for generating keywords and other metadata when developing for languages such as Vietnamese.Query::groupBy()
and Query::orderBy()
you can now use yii\db\Expression
: $expression = new Expression('SUBSTR(name, 2)'); $users = (new \yii\db\Query) ->from('user') ->orderBy($expression) ->limit(10) ->all();
'db' => [ 'dsn' => 'sqlite:@app/db/database.sqlite3', ]
join()
can now be used in joinWith()
: // join- orders.id $query->joinWith(['orders o'])->orderBy('o.id');
unsigned
support: 'createdBy' => $this->integer(10)->unsigned(),
$this->integer()->defaultExpression('CURRENT_TIMESTAMP');
./yii migrate/create
command ./yii migrate/create
become smarter. Based on the name of the migration being created and the parameters, she learned how to generate the migration code itself: ./yii migrate/create create_post --fields=title:string,body:text
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'); } }
getUserIdsByRole()
method has been added to the RBAC interface. It will certainly be useful in the development of the admin for roles and permissions.VarDumper::dump()
learned to work with the PHP magic method __debugInfo()
.$_ENV
and $_SERVER
on the error page. Displayed data is configured via yii\web\ErrorHandler::$displayVars
.yii\helpers\VarDumper::export()
learned how to work with circular references, which makes logging and debugging panel more reliable.Source: https://habr.com/ru/post/277201/
All Articles