Url::to()
and Url::toRoute()
: use yii\helpers\Url; Yii::setAlias('@posts', 'post/index'); // /index.php?r=post/index echo Url::to(['@posts']); echo Url::toRoute('@posts');
yii\caching\DbCache::db
or yii\web\CacheSession::cache
. Sometimes in order not to create a new component for unit testing, you may need to set such a property using the configuration array: $cache = Yii::createObject([ 'class' => 'yii\caching\DbCache', 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => '...', ], ]);
use yii\base\Object; use yii\db\Connection; use yii\di\Instance; class MyClass extends Object { public $db = 'db'; public function init() { $this->db = Instance::ensure($this->db, Connection::className()); } }
db
property with one of the following values:yii\db\Connection
;yii\db\Connection
.yii\behaviors\SluggableBehavior
, you can now set the new immutable
property to true
. In this case, the once created slug will not change when the model is saved again. This is useful for SEO: once indexed content will remain at the same URL.yii\jui\DatePicker
now automatically selects an alternative language if the specified language is not found. This is useful when you set the language
property as a locale ID that contains the region and / or option. For example, if you set language
in de-DE
and the widget does not find the language file /ui/i18n/datepicker-de-DE.js
, the language de
and the file /ui/i18n/datepicker-de.js
will automatically be used.yii\base\Model
class now contains the addErrors()
method, which allows you to pass the validation errors of one model to another. For example, if you have a form class for the ActiveRecord model and you need to pass form validation errors to the ActiveRecord model, you can do it like this: use yii\base\Model; use yii\db\ActiveRecord; class MyForm extends Model { public $model; public function process() { // ... if (!$this->validate()) { $this->model->addErrors($this->getErrors()); // .... } } }
Source: https://habr.com/ru/post/247741/
All Articles