I'm quite new to Yii2. I'm using advanced structure
I need to show a custom sql result in a view without using a model because I would like to display a 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(*) FROM v_risorse')->queryScalar();
$dataProvider = new SqlDataProvider([
'sql' => 'SELECT * FROM v_risorse',
'totalCount' => $totalCount,
'sort' =>false,
'pagination' => [
'pageSize' => 10,
],
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
At the following Url: http://localhost/advanced/frontend/web/index.php?r=vrisorse%2Findex
I have the error:
Not Supported – yii\base\NotSupportedException Message format 'number' is only supported for integer values. You have to install PHP intl extension to use this feature. 1. in C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\i18n\MessageFormatter.php
I tried to comment all the columns in gridview, and the error seems to be related to $dataProvider
variable
'COD_RISORSA','NOME', 'COGNOME'
are columns of the select.
You need to install PHP intl extension.i had the same error
given below is my working code in controller
and below is my view
You need to uncomment
and
in your php.ini, let me know if works
I met the same problem,It is easy to solve.You need assign the DB as bellow:
There documentation: https://www.yiiframework.com/doc/guide/2.0/en/output-data-providers#sql-data-provider
Example:
Create $dataProvider (controller):
Create GridView (view):