【问题标题】:YiiBooster modal Dataprovider UndefinedYiiBooster 模态 Dataprovider 未定义
【发布时间】:2014-02-11 09:43:49
【问题描述】:

我正在尝试使用 yiibooster 从模态窗口中的另一个模型视图加载索引视图,但该模型的数据提供者看起来是未定义的:

    <?php $this->beginWidget(
    'bootstrap.widgets.TbModal',
    array('id' => 'documentacion')
); ?>
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h4>Documentación</h4>
    </div>
    <?php 
        $doc = new ZfDocumentacionInmueble; 
        $this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc));
    ?>
    <div class="modal-footer">
        <?php $this->widget(
            'bootstrap.widgets.TbButton',
            array(
                'label' => 'Cerrar',
                'url' => '#',
                'htmlOptions' => array('data-dismiss' => 'modal'),
            )
        ); ?>
    </div>
<?php $this->endWidget(); ?>

    ERROR: Undefined variable: dataProvider

谢谢!

错误:

    C:\APP\htdocs\yii\yiitest\protected\views\zfDocumentacionInmueble\index.php(6)

1 <?php
2 /* @var $this ZfDocumentacionInmuebleController */
3 /* @var $dataProvider CActiveDataProvider */
4 
5 $this->widget('zii.widgets.CListView', array(
6     'dataProvider'=>$dataProvider,
7     'itemView'=>'_view',
8 )); ?>

控制器代码:

public function actionIndex()
    {
        $dataProvider=new CActiveDataProvider('ZfDocumentacionInmueble');
        $this->render('index',array(
            'dataProvider'=>$dataProvider,
        ));
    }

【问题讨论】:

  • 您没有更多信息吗?就像你在哪一行得到错误?我真的没有看到任何与 dataProvider 相关的内容,除非 ZfDocumentationInmueble 包含某些内容。
  • 我尝试使用真实的 url,一切正常 www.example.com/ZfDocumentacionInmueble/index

标签: yii frameworks widget yii-booster


【解决方案1】:

如果“真实 url”有效,那么 ZfDocumentacionInmueble::actionIndex()-function 正在创建一个 $dataProvider 并将其传递给视图。

在您的 renderPartial 调用中,您没有传递 $dataProvider。如果您在控制器操作中创建了它,请务必将其传递(否则您可能必须从其他控制器复制代码):

$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider));

【讨论】:

  • 您的控制器操作是否真的创建了一个 dataProvider?如果一开始没有将其传递给您的视图,那么仅进行我建议的更改不会改变任何内容
  • 您确定您没有将此视图呈现为另一个视图的一部分吗?如果您在所有视图中巧妙地传递 $dataProvider,则不应出现该错误
  • 是的,我正在另一个模型视图中渲染它,也许我没有正确解释自己,抱歉
  • 那么你也必须在那里传递 $dataProvider ,就像我展示的那样。对于每个渲染(部分)调用,变量只会下降 1 级。
  • $this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider)); ???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
相关资源
最近更新 更多