gpt4 book ai didi

php - Yii2 renderAjax 嵌套Listview

转载 作者:可可西里 更新时间:2023-10-31 23:39:12 25 4
gpt4 key购买 nike

我正在尝试通过 ajax 呈现 ListView ,但它给了我以下错误:

Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message &#039
;The "dataProvider" property must be set.

Controller :

public function actionLoadListviewAjax()
{
$dataProvider = // call to a function which returns ArrayDataProvider
return $this->renderAjax('myview', [ 'dataProvider' => $dataProvider ]);
}

查看:

echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'items',
'options' => ['class' => 'list-view-post'],
'summary' => '',
'emptyText' => '',
]);

$dataProvder:

<pre>yii\data\ArrayDataProvider Object
(
[key] =>
[allModels] => Array
(
[0] => Array
(
[RecommendationCategory] =>
[ID] => 37
[GUID] =>
[Title] => test
[WallPostTypeID] => 1
[RecommendationCategoryID] => 0
[CommentsJSON] =>
[TotalComments] =>
[PostedMessage] => test
[FirstName] => test
[LastName] => test
[ProfileImagePath] => Lighthouse.jpg
[AddedOn] => 2015-07-18 15:14:06
[ImagePath] =>
[CommentProfileImagePath] =>
[IsSubscribe] => 1
)

)

[id] =>
[_sort:yii\data\BaseDataProvider:private] =>
[_pagination:yii\data\BaseDataProvider:private] =>
[_keys:yii\data\BaseDataProvider:private] =>
[_models:yii\data\BaseDataProvider:private] =>
[_totalCount:yii\data\BaseDataProvider:private] =>
[_events:yii\base\Component:private] => Array
(
)

[_behaviors:yii\base\Component:private] =>
)

我也尝试了 renderPartial 但仍然是同样的错误。有什么想法为什么会给出异常(exception)吗?

更新:

在我的 itemView 文件 items 中,我有另一个 ListView ,它给出了异常。

最佳答案

实际上, ListView 项不必访问已通过小部件发送的外部变量。但是,如果您必须在内部 View 文件中使用 $dataProvider 变量,请尝试使用 callable 在 ListView 中显示项目。

像这样:

```

echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => function ($model, $key, $index, $widget) {
return $this->renderAjax('items', [
'dataProvider' => $widget->dataProvider,
]);
},
'options' => ['class' => 'list-view-post'],
'summary' => '',
'emptyText' => '',
]);

```

更多信息在这里

http://www.yiiframework.com/doc-2.0/yii-widgets-listview.html# $itemView-详细信息

关于php - Yii2 renderAjax 嵌套Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31491820/

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