php - Yii2 custom sql query in gridview -
i'm quite new yii2. i'm using advanced structure
i need show custom sql result in view without using model because display sql view.
index.php
<?= gridview::widget([ 'dataprovider' => $dataprovider, 'columns' => [ ['class' => 'yii\grid\serialcolumn'], 'cod_risorsa', [ 'label' =>"nome", 'attribute' => 'nome', 'value'=>function($data){ return $data["nome"]; } ], 'cognome', ['class' => 'yii\grid\actioncolumn'], ], ]); ?>
vrisorsecontroller.php
public function actionindex() { $totalcount = yii::$app->db->createcommand('select count(*) v_risorse')->queryscalar(); $dataprovider = new sqldataprovider([ 'sql' => 'select * v_risorse', 'totalcount' => $totalcount, 'sort' =>false, 'pagination' => [ 'pagesize' => 10, ], ]); return $this->render('index', [ 'dataprovider' => $dataprovider, ]); }
at following url: http://localhost/advanced/frontend/web/index.php?r=vrisorse%2findex
i have error:
not supported – yii\base\notsupportedexception message format 'number' supported integer values. have install php intl extension use feature. 1. in c:\xampp\htdocs\advanced\vendor\yiisoft\yii2\i18n\messageformatter.php
i tried comment columns in gridview, , error seems related $dataprovider
variable
'cod_risorsa','nome', 'cognome'
columns of select.
you need install php intl extension.i had same error
given below working code in controller
$count = yii::$app->db->createcommand(' select count(*) screen_ticket_booking_history status=:status ', [':status' => 0])->queryscalar(); $sql = "select a1.booking_id booking_id, a1.booking_date booking_date, a2.movie_name movie, a3.theatre_name theatre, a1.amount amount screen_ticket_booking_history a1 left outer join movies a2 on a1.movie_id=a2.id left outer join theatres a3 on a1.theatre_id=a3.id left outer join users_backend a4 on a3.users_backend_id=a4.id a1.booking_date = '{$day}' , a1.movie_id='{$movies->id}'"; //~ $models = $dataprovider->getmodels(); //print_r($models);die(); if( $userid != '1') { $sql .= " , a3.users_backend_id = '{$userid}' "; } $dataprovider = new sqldataprovider([ 'sql' => $sql, 'totalcount' => $count, ]); return $this->render('index', [ 'model' => $model, 'dataprovider' => $dataprovider, ]); }
and below view
<?= gridview::widget([ 'dataprovider' => $dataprovider, 'columns' => [ ['class' => 'yii\grid\serialcolumn'], 'booking_id', 'booking_date', 'movie', 'theatre', 'amount', //~ ['class' => 'yii\grid\actioncolumn'], ], ]); ?>
Comments
Post a Comment