$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 redirect to previous page or referrer
YII2 redirect to previous page or referrer $this->redirect(Yii::$app->request->referrer);
YII2 find value from db between a range
YII2 find value from db between a range $match_batches=Batches::find() ->andFilterWhere( [ ‘>’,’start_date’, $temp_date_range_start ] ) ->andFilterWhere( [ ‘<‘,’end_date’, $temp_date_range_end ] )->one();
JQuery check if checkbox is checked or not
if($(“#checkboxid”).prop(‘checked’) == true){ //do something}
YII2 Gridview how to add jui datepicker in filter
[ ‘attribute’ => ‘slot_date’, ‘value’ => ‘slot_date’, ‘filter’ => yiijuiDatePicker::widget([ ‘language’ => ‘en’, ‘dateFormat’ => ‘yyyy-MM-dd’, ‘model’ => $searchModel, ‘attribute’ => ‘slot_date’, ] ), ‘format’ => ‘html’, ],
YII2 gridview how to add drop down in filter
[ ‘attribute’=>’column_name’, ‘filter’=>array( “value1″=>”label1”, “value2″=>”label2”, “value3″=>”label3”), ]
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(); } }
Yii 2.0: Displaying, Sorting and Filtering Model Relations on a GridView, Gridview with relationships
One of the things you will find tricky to implement is the the sorting and filtering of a GridView’s column that displays related model data. As you know if you have been playing with Yii2 lately, there is a new proposed way to search for data and is by using objects that extend from the… Continue reading Yii 2.0: Displaying, Sorting and Filtering Model Relations on a GridView, Gridview with relationships
How to import an SQL file using the command line in MySQL?
How to import an SQL file using the command line in MySQL? mysql -u username -p database_name < /path/file.sql It will ask for password after this command
YII2 nav widget open link in new tab/window and how to link to external link
echo Nav::widget([ ‘options’ => [‘class’ => ‘nav navbar-left nav-tabs’], ‘items’ => [ [ ‘label’ => ‘Schedule An Appointment’, ‘url’ => ‘http://google.com’, ‘linkOptions’ => [‘target’ => ‘_blank’] ], ], ]);