我有一个组合了许多模型的视图,我制作了一个选项卡,每个选项卡都包含不同的模型
这是我在视图上的脚本
<?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属性"pln.merk"未定义。
在有些奇怪的地方,PLN 是我的模型,Merk 不是来自 PLN 的列之一,而是来自另一个模型 ATS,我基于 ATS 制作了这个视图文件,其中包含 Merk 列,但是当我所做的所有视图渲染部分像发电机组、UPS、ATS 工作正常时,这没有意义
只有 PLN 和其他几个模型会抛出错误消息,例如它们不知何故无法识别 PLN 的模型列,而是从 ATS 模型中读取错误的列
编辑:
基本上视图是由CRUD生成的,这是admin.php文件,其中包含CGridView
<?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',
),
),
)); ?>
苯丙胺类兴奋剂.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
),*/
),
)
)
?>
我已经
解决了这个问题,所以我使用 crud 生成器在下面创建高级搜索选项代码,'model'=>$model 覆盖所需的模型,所以如果你使用 crud 生成器,我必须删除下面的这段代码
<?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作为控制器文件的加载模型中的主键标识符