renderPartial不同的模型Yii几个模型工作但不是全部

时间:2014-12-30 10:12:20

标签: php yii renderpartial

我有一个结合了许多模型的视图,我制作了一个每个包含不同模型的标签

这是我在视图中的脚本

<?php 
$this->widget(
        'booster.widgets.TbTabs',
        array(
            'type' => 'tabs',
            'tabs' => array(
                array(
                    'label'=>'Genset',
                    'content'=>$this->renderPartial('/ats/genset', array('model'=>new genset), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'ATS',
                    'content'=>$this->renderPartial('/ats/ats', array('model'=>new ats), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'UPS',
                    'content'=>$this->renderPartial('/ats/ups', array('model'=>new ups), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'PLN',
                    'content'=>$this->renderPartial('/ats/pln', array('model'=>new pln), true ),
                    'active'=> false
                ),
            ),
        )
)
?>

在最后一个标签上,标签名称是PLN不起作用并返回错误

了CException 物业&#34; pln.merk&#34;未定义。

哪里有奇怪的东西,pln是我的模型,而merk不是来自pln的列,而是来自ats的另一个模型,我根据具有merk列的ats创建了这个视图文件,但这并不是&#39 ; t当所有视图我做genPartial像Genset,UPS,ATS工作正常

只有pln和其他几个模型抛出错误信息,就像他们不知道pln的模型列,而是从ats模型中读取错误的列

编辑:

基本上视图是由CRUD生成的,这是包含CGridView的admin.php文件

<?php
/* @var $this PlnController */
/* @var $model pln */

$this->breadcrumbs=array(
    'Plns'=>array('index'),
    'Manage',
);

$this->menu=array(
    array('label'=>'List pln', 'url'=>array('index')),
    array('label'=>'Create pln', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});
$('.search-form form').submit(function(){
    $('#pln-grid').yiiGridView('update', {
        data: $(this).serialize()
    });
    return false;
});
");
?>

<h1>Manage Plns</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
    'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'pln-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'siteid',
        'capacity',
        'arus_r',
        'arus_s',
        'arus_t',
        /*
        'id_pelanggan',
        'jumlah_fasa',
        */
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

ATS.php

<?php
/* @var $this AtsController */
/* @var $model ats */

$this->breadcrumbs=array(
    'Ats'=>array('index'),
    'Manage',
);

$this->menu=array(
    array('label'=>'List ats', 'url'=>array('index')),
    array('label'=>'Create ats', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});
$('.search-form form').submit(function(){
    $('#ats-grid').yiiGridView('update', {
        data: $(this).serialize()
    });
    return false;
});
");
?>

<h1>Dapot</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php 
$this->widget(
        'booster.widgets.TbTabs',
        array(
            'type' => 'tabs',
            'tabs' => array(
                array(
                    'label'=>'Genset',
                    'content'=>$this->renderPartial('/ats/genset', array('model'=>new genset), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'ATS',
                    'content'=>$this->renderPartial('/ats/ats', array('model'=>new ats), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'UPS',
                    'content'=>$this->renderPartial('/ats/ups', array('model'=>new ups), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'Rectifier',
                    'content'=>$this->renderPartial('/ats/rectifier', array('model'=>new rectifier), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'Baterai',
                    'content'=>$this->renderPartial('/ats/baterai', array('model'=>new baterai), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'BBS',
                    'content'=>$this->renderPartial('/ats/bbs', array('model'=>new bbs), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'Inverter',
                    'content'=>$this->renderPartial('/ats/inverter', array('model'=>new inverter), true ),
                    'active'=> false
                ),
                array(
                    'label'=>'Trafo',
                    'content'=>$this->renderPartial('/ats/trafo', array('model'=>new trafo), true ),
                    'active'=> false
                ),
                /*array(
                    'label'=>'PLN',
                    'content'=>$this->renderPartial('/ats/pln', array('model'=>new PLN), true ),
                    'active'=> false
                ),*/
            ),
        )
)
?>

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,所以我使用crud生成器创建下面的高级搜索选项代码, 'model'=&gt; $ model会覆盖所需的模型,所以如果你使用crud generator我必须删除下面这段代码

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
    'model'=>$model,
)); ?>
</div><!-- search-form -->

之后,我尝试使用搜索功能,但它不起作用,所以我为每个视图添加了取消设置的属性

$model_x=new model_x('search');
$model_x->unsetAttributes();
if(isset($_GET['model_x']))
            $model_x->attributes=$_GET['model_x'];

现在我停留在视图,更新,删除它始终使用ats作为控制器文件中loadModel的主键标识符