我的actionCreate和actionUpdate看起来非常相似。这对我的actionCreate工作正常,但我的actionUpdate没有看到声明的变量。 Undefined variable: attr
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$attr = new ProductAttribute();
if(isset($_POST['Product']))
{
$model->update_date = time();
$model->product_approval_status = "N";
//blah blah blah all about this product model
}
//attributes here
$valid = true;
$arrAttrData = array();
if($model->save()){
if(isset($_POST['ProductAttribute'])){
foreach($_POST['ProductAttribute'] as $i=>$attrItem){
$attr = new ProductAttribute;
$attr->attributes = $attrItem;
if ( $model->product_id )
$attr->product_id = $model->product_id;
if ( $attr->validate() )
$attr->save();
}
}
unset($attr);
}
$this->render('update',array(
'model'=>$model,
'attr'=>$attr
));
}
答案 0 :(得分:-1)
您应该删除该行
unset($attr);