【发布时间】:2014-12-30 10:12:19
【问题描述】:
我有一个结合了许多模型的视图,我制作了一个标签,每个标签都包含不同的模型
这是我在视图中的脚本
<?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 的标签不起作用并返回这样的错误
C异常 未定义属性“pln.merk”。
有一些奇怪的地方,pln 是我的模型,merk 不是 pln 中的列之一,而是来自 ats 的另一个模型,我基于具有 merk 列的 ats 制作了这个视图文件,但这不是当我渲染部分的所有视图(如发电机组、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><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></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><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></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
),*/
),
)
)
?>
【问题讨论】:
-
您会发布
pln视图文件(并且可能是ats视图文件)吗?
标签: php yii renderpartial