Skip to main content

Posts

Showing posts with the label YII2

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 9 10 11 12 13 14 15 16 17 18 <? = $form -> field ( $model , 'country_id' ) -> dropDownList ([ "5" => 'USA' , "6" => "Pakistan" ], [ 'prompt' => 'Select Country' , 'onchange' => ' $.get( "' . \yii\helpers\Url :: 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' , ] ...

Yii2 REST API remove tag

$xml = new \ yii \ web \ XmlResponseFormatter ; $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  yii\grid\GridView , add it to the  columns  configuration as follows: 'columns'  => [      // ...      [          'class'  =>  'yii\grid\CheckboxColumn' ,          // 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' => 'yii\grid\CheckboxColumn' ], 'id' , ], ]); ?> <?= Html :: endForm...

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 function tableName() {