i hav two tables, there are table krs and table nilai1.
when i save the model of table krs, i hope the id(PK) of table krs can also be inserted to id_krs (table nilai1).
The structure of tables :
table krs
id(PK) | attribute1 | attribute2 |
table nilai1
id(PK) | id_krs(FK) | attribute3 | attribute4 |
Here the modification of KrsController.php
public function actionCreate()
{
$model=new Krs;
$model2=new Nilai1;
if(isset($_POST['Krs']))
{
$transaction=$model->dbConnection->beginTransaction();
try{
$model->attributes=$_POST['Krs'];
if($model->save()){
$model2->id_krs=$model->getPrimaryKey;
if($model2->save())
//print_r($model->getErrors()); die();
$this->redirect(array('view','id'=>$model->id));
}
else
{
throw new CException($model->getErrors());
}
$transaction->commit();
Yii::app()->end();
}
catch(CException $er){
$transaction->rollBack();
}
}
$this->render('create',array(
'model'=>$model,'model2'=>$model2,
));
}
but, the result not like i want, not saving anything to the tables…
Somebody can help me???