我對Yii2相當陌生。 我正在使用高級結構在gridview中Yii2自定義sql查詢
我需要在視圖中顯示自定義的sql結果而不使用模型,因爲我想顯示一個sql視圖。
的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,
]);
}
以下網址: http://localhost/advanced/frontend/web/index.php?r=vrisorse%2Findex
我有錯誤:
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
我試圖評論gridview中的所有列,並且該錯誤似乎與$dataProvider
變量
'COD_RISORSA','NOME', 'COGNOME'
是select的列。
錯誤似乎與國際功能,請張貼你的配置。 – scaisEdge
在您的'php.ini'中取消註釋'extension = php_intl.dll'並重新啓動webserver – user1852788