0

I am trying to load the index view from another model view in a modal window using yiibooster but the dataprovider of this model looks like it is undefined:

    <?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

thanks!

ERROR:

    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 )); ?>

CONTROLLER CODE:

public function actionIndex()
    {
        $dataProvider=new CActiveDataProvider('ZfDocumentacionInmueble');
        $this->render('index',array(
            'dataProvider'=>$dataProvider,
        ));
    }
Sergio_HW
  • 155
  • 3
  • 18
  • Don't you have more information? Like on what line you get the error? I don't really see anything dataProvider related, unless the ZfDocumentationInmueble contains something. – Blizz Feb 11 '14 at 09:49
  • I tried using the real url, and everything goes fine www.example.com/ZfDocumentacionInmueble/index – Sergio_HW Feb 11 '14 at 09:52

1 Answers1

0

If the "real url" works, then the ZfDocumentacionInmueble::actionIndex()-function is creating a $dataProvider and passing it to the view.

In your renderPartial call, you do not pass on a $dataProvider. If you have created it in your controller action, be sure to pass it along (or otherwise you might have to copy the code from the other controller):

$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider));
Blizz
  • 8,082
  • 2
  • 33
  • 53
  • Does your controller action actually create a dataProvider? Just making the change I suggested will not change anything if it is not passed to your view in the first place – Blizz Feb 11 '14 at 10:01
  • And your sure you are not rendering this view as part of another view? If you pass on the $dataProvider neatly amongst all views, you should not get that error – Blizz Feb 11 '14 at 10:10
  • Yes i am rendering this inside another model view, maybe i didn't explain myself properly, sorry – Sergio_HW Feb 11 '14 at 10:12
  • Well then you have to pass on the $dataProvider there as well, in the same way as what I showed. The variables only go 1 level down for each render(Partial) call. – Blizz Feb 11 '14 at 10:12
  • $this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider)); ??? – Sergio_HW Feb 11 '14 at 10:14
  • In your view, do a var_dump($dataProvider). If that says undefined you are not getting it from the controller. – Blizz Feb 11 '14 at 10:16
  • I tried and as you said i am not getting from the controller, i tried $docus =new CActiveDataProvider('ZfDocumentacionInmueble'); and it takes the datas from the main model called "zfInmuebles" and not from ZfDocumentacionInmubles model. – Sergio_HW Feb 11 '14 at 11:01
  • $this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc,'dataProvider' => $docus)); – Sergio_HW Feb 11 '14 at 11:02