遵循本教程;当我尝试让数据显示在表单中并更新时
因为我的错误是:
$n = $this->loadModel($id);
我想用一种形式制作两个模型,这是我的更新代码:
控制器:
public function actionUpdate($id)
{
$n = new Noticias;
$m = new Multimedia;
$this->performAjaxValidation(array($n,$m));
$n=$this->loadModel($id);
if(isset($_POST['Noticias'],$_POST['Multimedia']))
{
$n->attributes=$_POST['Noticias'];
$m->attributes=$_POST['Multimedia'];
$m->ID_NOT=$n->ID;
$m->setIsNewRecord(false);
if($n->save())
$this->redirect(array('admin','id'=>$n->ID));
}
$this->render('update',array('n'=>$n,'m'=>$m));
}
更新.php
<?php echo $this->renderPartial('_form', array('n'=>$n, 'm'=>$m)); ?>
一些看法
//get Multimedia FK
<?php if ($n->isNewRecord==false) {
$m=Multimedia::model()->findByPk($n->ID);
} ?>
//Validation
<?php echo $form->errorSummary(array($n,$m)); ?>
//Field FOTO between other
<div class="row">
<?php echo $form->labelEx($m,'FOTO_URL'); ?>
<?php echo $form->textField($m,'FOTO_URL',array('size'=>25,'maxlength'=>100)); ?>
<?php echo $form->error($m,'FOTO'); ?>
</div>