gpt4 book ai didi

php - gridview 中的 Yii2 自定义 sql 查询

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:38:15 25 4
gpt4 key购买 nike

我是 Yii2 的新手。我正在使用高级结构

我需要在不使用模型的情况下在 View 中显示自定义 sql 结果,因为我想显示 sql View 。

索引.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' 是选择的列。

最佳答案

你需要安装PHP intl扩展。我有同样的错误

下面是我的工作代码在 Controller 中

$count      =   Yii::$app->db->createCommand('
SELECT COUNT(*) FROM screen_ticket_booking_history WHERE status=:status
', [':status' => 0])->queryScalar();

$sql = "SELECT A1.booking_id As Booking_id,
A1.booking_date As Booking_date,
A2.movie_name As Movie,
A3.theatre_name As Theatre,
A1.amount As Amount

FROM
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

WHERE A1.booking_date = '{$day}'
AND A1.movie_id='{$movies->id}'";


//~ $models = $dataProvider->getModels(); //print_r($models);die();
if( $userid != '1')
{
$sql .= " AND A3.users_backend_id = '{$userid}' ";
}

$dataProvider = new SqlDataProvider([
'sql' => $sql,
'totalCount' => $count,
]);
return $this->render('index',
[ 'model' => $model,
'dataProvider' => $dataProvider,
]);
}

下面是我的看法

<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'Booking_id',
'Booking_date',
'Movie',
'Theatre',
'Amount',
//~ ['class' => 'yii\grid\ActionColumn'],
],
]); ?>

关于php - gridview 中的 Yii2 自定义 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29945259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com