加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Yii2 renderAjax嵌套Listview

发布时间:2020-12-13 15:57:18 所属栏目:PHP教程 来源:网络整理
导读:我试图通过ajax呈现listview,但它给了我以下错误: Exception (Invalid Configuration) #039;yiibaseInvalidConfigException#039; with message #039;The quot;dataProviderquot; property must be set. 控制器: public function actionLoadListviewAjax(
我试图通过ajax呈现listview,但它给了我以下错误:

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

控制器:

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>yiidataArrayDataProvider 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:yiidataBaseDataProvider:private] => 
    [_pagination:yiidataBaseDataProvider:private] => 
    [_keys:yiidataBaseDataProvider:private] => 
    [_models:yiidataBaseDataProvider:private] => 
    [_totalCount:yiidataBaseDataProvider:private] => 
    [_events:yiibaseComponent:private] => Array
        (
        )

    [_behaviors:yiibaseComponent:private] => 
)

我也尝试了renderPartial,但仍然是同样的错误.任何想法为什么它给出了这个例外?

更新:

在我的itemView文件项中,我有另一个列表视图,它给出了异常.

解决方法

实际上,列表视图项不必访问已通过窗口小部件发送的外部变量.
但是,如果必须在内部视图文件中使用$dataProvider变量,请尝试使用callable在列表视图中显示项目.

这样的事情:

“`

echo ListView::widget([
    'dataProvider' => $dataProvider,'itemView'     => function ($model,$key,$index,$widget) {
        return $this->renderAjax('items',[
            'dataProvider' => $widget->dataProvider,]);
    },]);

“`

更多信息在这里

http://www.yiiframework.com/doc-2.0/yii-widgets-listview.html# $ItemView控件细节

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读