如何解决页面上没有数据显示为什么会这样?Php / Yii2
这是DebtController.php的一部分,应从数据库中获取数据
public function actionCurrent()
{
$userId = Yii::$app->user->id;
$debtData = Debt::find()
->select([
'currency_id','depositConfirmedAmount' => 'IF((to_user_id = ' . $userId . ') && (status = ' . Debt::STATUS_CONFIRM . '),amount,0)','creditConfirmedAmount' => 'IF((from_user_id = ' . $userId . ') && (status = ' . Debt::STATUS_CONFIRM . '),])
->andWhere([
'OR',['from_user_id' => $userId],['to_user_id' => $userId]
]);
$dataProvider = new ActiveDataProvider([
'query' => Debt::find()
->from(['debtData' => $debtData])
->select([
'currency_id','depositConfirmed' => 'SUM(debtData.depositConfirmedAmount)','creditConfirmed' => 'SUM(debtData.creditConfirmedAmount)',])
->groupBy(['currency_id']),]);
return $this->render('index',[
'dataProvider' => $dataProvider,]);
}
此部分不在index.php中输出数据。 这是应该向其输出数据的表。
<?= GridView::widget([
'dataProvider' => $dataProvider,'summary' => false,'tableOptions' => ['class' => 'table table-hover'],'columns' => [
[
'label' => 'Currency','value' => function (Debt $data) {
return $data->currency->code ?? null;
},'format' => 'html',],[
'label' => 'My Deposits','value' => function (Debt $data) {
$text = $data->depositConfirmed;
return Html::a($text,['/debt/view','direction' => Debt::DIRECTION_DEPOSIT,'currencyId' => $data->currency_id]);
},[
'label' => 'My Credits','value' => function (Debt $data) {
$text = $data->creditConfirmed;
return Html::a($text,'direction' => Debt::DIRECTION_CREDIT,]
如果我存储$ dataProvider,则将其打印出来。 这是经编辑的注释,可以帮助您解决此问题。
object(yii\data\ActiveDataProvider)#172 (12) {
["query"]=>
object(app\models\queries\DebtQuery)#177 (33) {
["sql"]=>
NULL
["on"]=>
NULL
["joinWith"]=>
NULL
["select"]=>
array(3) {
["currency_id"]=>
string(11) "currency_id"
["depositConfirmed"]=>
string(36) "SUM(debtData.depositConfirmedAmount)"
["creditConfirmed"]=>
string(35) "SUM(debtData.creditConfirmedAmount)"
}
["selectOption"]=>
NULL
["distinct"]=>
NULL
["from"]=>
array(1) {
["debtData"]=>
object(app\models\queries\DebtQuery)#164 (33) {
["sql"]=>
NULL
["on"]=>
NULL
["joinWith"]=>
NULL
["select"]=>
array(3) {
["currency_id"]=>
string(11) "currency_id"
["depositConfirmedAmount"]=>
string(49) "IF(((to_user_id = 1) && (status = 1)),0)"
["creditConfirmedAmount"]=>
string(51) "IF(((from_user_id = 1) && (status = 1)),0)"
}
["selectOption"]=>
NULL
["distinct"]=>
NULL
["from"]=>
NULL
["groupBy"]=>
NULL
["join"]=>
NULL
["having"]=>
NULL
["union"]=>
NULL
["withQueries"]=>
NULL
["params"]=>
array(0) {
}
["queryCacheDuration"]=>
NULL
["queryCacheDependency"]=>
NULL
["_events":"yii\base\Component":private]=>
array(0) {
}
["_eventWildcards":"yii\base\Component":private]=>
array(0) {
}
["_behaviors":"yii\base\Component":private]=>
array(0) {
}
["where"]=>
array(3) {
[0]=>
string(2) "OR"
[1]=>
array(1) {
["from_user_id"]=>
int(1)
}
[2]=>
array(1) {
["to_user_id"]=>
int(1)
}
}
["limit"]=>
NULL
["offset"]=>
NULL
["orderBy"]=>
NULL
["indexBy"]=>
NULL
["emulateExecution"]=>
bool(false)
["modelClass"]=>
string(15) "app\models\Debt"
["with"]=>
NULL
["asArray"]=>
NULL
["multiple"]=>
NULL
["primaryModel"]=>
NULL
["link"]=>
NULL
["via"]=>
NULL
["inverseOf"]=>
NULL
["viaMap":"yii\db\ActiveQuery":private]=>
NULL
}
}
["groupBy"]=>
array(1) {
[0]=>
string(11) "currency_id"
}
["join"]=>
NULL
["having"]=>
NULL
["union"]=>
NULL
["withQueries"]=>
NULL
["params"]=>
array(0) {
}
["queryCacheDuration"]=>
NULL
["queryCacheDependency"]=>
NULL
["_events":"yii\base\Component":private]=>
array(0) {
}
["_eventWildcards":"yii\base\Component":private]=>
array(0) {
}
["_behaviors":"yii\base\Component":private]=>
array(0) {
}
["where"]=>
NULL
["limit"]=>
NULL
["offset"]=>
NULL
["orderBy"]=>
NULL
["indexBy"]=>
NULL
["emulateExecution"]=>
bool(false)
["modelClass"]=>
string(15) "app\models\Debt"
["with"]=>
NULL
["asArray"]=>
NULL
["multiple"]=>
NULL
["primaryModel"]=>
NULL
["link"]=>
NULL
["via"]=>
NULL
["inverseOf"]=>
NULL
["viaMap":"yii\db\ActiveQuery":private]=>
NULL
}
["key"]=>
NULL
["db"]=>
NULL
["id"]=>
NULL
["_sort":"yii\data\BaseDataProvider":private]=>
NULL
["_pagination":"yii\data\BaseDataProvider":private]=>
NULL
["_keys":"yii\data\BaseDataProvider":private]=>
NULL
["_models":"yii\data\BaseDataProvider":private]=>
NULL
["_totalCount":"yii\data\BaseDataProvider":private]=>
NULL
["_events":"yii\base\Component":private]=>
array(0) {
}
["_eventWildcards":"yii\base\Component":private]=>
array(0) {
}
["_behaviors":"yii\base\Component":private]=>
NULL
}
数据在数据库中,但是我不能从那里获取数据
可能是什么错误?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。