Yii2 . FORM How to make dependant drop down. Where second drop downs values are dependant on first drop down selection

In form file : 1 2 3 4 5 6 7 8 9101112131415161718 <?= $form->field($model, ‘country_id’)->dropDownList([“5″=>’USA’, “6”=>”Pakistan”], [‘prompt’=>’Select Country’, ‘onchange’=>’ $.get( “‘.yiihelpersUrl::toRoute(‘/site/getstates’).'”, { id: $(this).val() } ) .done(function( data ) { $( “#’.Html::getInputId($model, ‘state_id’).'” ).html( data ); } ); ‘,’class’ => ‘form-control’ ] ); ?> <?= $form->field($model, ‘state_id’) ->dropDownList( [ ‘prompt’=>’Select State’, ] ); ?>… Continue reading Yii2 . FORM How to make dependant drop down. Where second drop downs values are dependant on first drop down selection

Yii2 REST API remove tag

$xml = new yiiwebXmlResponseFormatter;$xml->rootTag = ‘Response’;        Yii::$app->response->format = ‘custom_xml’;Yii::$app->response->formatters[‘custom_xml’] = $xml;        return [‘customer’ => [‘name’ => ‘John Smith’]];

Yii2 Gridview bulk action using checkbox column. How to properly create checkbox column in gridview for bulk actions

To add a CheckboxColumn to the yiigridGridView, add it to the columns configuration as follows: ‘columns’ => [    // …    [        ‘class’ => ‘yiigridCheckboxColumn’,        // you may configure additional properties here    ],] This is the view: <?=Html::beginForm([‘controller/bulk’],’post’);?><?=Html::dropDownList(‘action’,”,[”=>’Mark selected as: ‘,’c’=>’Confirmed’,’nc’=>’No Confirmed’],[‘class’=>’dropdown’,])?><?=Html::submitButton(‘Send’, [‘class’ => ‘btn btn-info’,]);?><?=GridView::widget([‘dataProvider’ => $dataProvider,’columns’ => [[‘class’ => ‘yiigridCheckboxColumn’],’id’,],]); ?><?= Html::endForm();?> This is the controller: public function actionBulk(){ $action=Yii::$app->request->post(‘action’); $selection=(array)Yii::$app->request->post(‘selection’);//typecasting foreach($selection as $id){ $e=Evento::findOne((int)$id);//make a typecasting //do your stuff $e->save(); } }

Yii2 query / query builder: how to use OR condition

Yii2 query / query builder: how to use OR condition You can use some thing like this: $third_res_count=CustomerReservedTimeslots::find() ->select([‘COUNT(timeslot_id) AS cnt’]) ->where([ ‘test_date’ => $today_date, ‘confirmed’ => ‘1’, ]) ->andWhere([‘>’, ‘third_user_id’, ‘0’]) ->andFilterWhere([ ‘or’, [‘like’, ‘status’, ‘checked in’], [‘like’, ‘status’, ‘Waiting for check in’], ]) ->one();

YII2 DB Count Results query

YII2 DB count results query Simple in the controller or view file add do this: $count=MODEL::find()   ->select([‘COUNT(id) AS cnt’])   ->where([   ‘field1’ => $value1, ])-> andWhere([‘>’, ‘field2’, $value2]) ->one()->cnt; And in the model of the table add before this line: public static function tableName() Add public $cnt; like below: public $cnt; public static… Continue reading YII2 DB Count Results query