我無法在控制器中爲某些基本功能輸出動作佈局。我有一個提供帳戶基本信息的視圖。帳戶跨越多個領域,因此用戶最有可能經常進行保存。我所經歷的是,每次我進行保存時,都會創建一個新行。 actionCreate被調用,它只是在表中的數據轉儲。我一定會保持用戶在所有數據填充在同一接口。Yii:控制器在同一動作方法中處理記錄創建和更新的操作
從我迄今爲止收集的,我不能有actionCreate方法的操作參數,因爲它失敗,因爲它是第一次保存爲空。
繼從我actionCreate控制方法的代碼片段:
public function actionCreate()
{
$model=new Account;
$accaddress=new AccAddress;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Account'],$_POST['AccAddress']))
{
$model->attributes=$_POST['Account'];
if($model->save()) //Account data saving
if (isset($_POST['AccAddress'])){
//Yii::log('Dumping infomration for multiple models.');
$accaddress->attributes=$_POST['AccAddress'];
$accaddress->acc_id=$model->id;
if ($pataddress->save()){//Account address saving
}
//$this->redirect(array('create','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
'accaddress'=>$accaddress,
'tabss'=>$tabarray,
));
}
焦急期待的建議/意見。提前致謝。
問候,費薩爾
您需要發佈代碼才能查看您做錯了什麼,但網絡上的任何教程都會在此階段爲您提供幫助。 – Pentium10
@Pentium,請看看,我只是添加了代碼。 – FaisalKhan
你的模型在哪裏:findByPk()調用來加載現有的記錄? – Pentium10