yii2
How to add a class to tags in a GridView
For example [ ‘attribute’ => ‘name’, ‘contentOptions’ => [‘class’ => ‘text-center’], ‘headerOptions’ => [‘class’ => ‘text-center’] ], contentOptions – for td cells, headerOptions – for th cells Reference: Yii2 Docs | Column classes in GridView
Yii2 – ActiveRecord to Array
Try this! $model = Post::find($id)->limit(10)->asArray()->all(); $model = Post::find($id)->select(‘id,name as full’)->asArray()->one(); $model = Post::find($id)->select(‘id,name as full’)->asArray()->all(); $model = Post::find()->where([‘slug’=>$slug])->asArray()->one();
Yii2: update field with query builder
Create command can be used directly as follows : \Yii::$app->db->createCommand(“UPDATE table SET column1=:column1, column2=:column2 WHERE id=:id”) ->bindValue(‘:id’, your_id) ->bindValue(‘:column1’, :column1_value) ->bindValue(‘:column2’, :column2_value) ->execute();
How to change label text of the ActiveField?
<?= $form->field($model, ‘username’)->textInput()->label(‘My superb label’) ?> http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#label()-detail
How to use constant in the ON condition in Yii2 hasMany relation
In this case you can modify ON condition with andOnCondition method: public function getImages() { return $this->hasMany(RecipeImage::className(), [‘imageable_id’ => ‘id’]) ->andOnCondition([‘imageable_type’ => ‘Person’]); } Official docs: andOnCondition: