Hi community,
I’m trying to save a record to a table B (I have defined Model B with Gii), in my method ActionCreate of ControllerTableA after the save method which save the current record in TableA.
When I did the code listed below, I had a record with null values in my tableB.
Of course the record saved in TableA was correct.
The TableA is parent of TableB and the fields of TableB are also in TableA.
TableB has some fields with values of TableA plus some other constant values.
Here is the code in ControllerTableA:
private $_tablaB;
public function actionCreate()
{
$model=new TABLE_A;
if(isset($_POST['tableA']))
{
$model->attributes=$_POST['tableA'];
if($model->save()) {
$this->_tableB = new tablaB; Model TableB
$this->_tableB->attributes = array('id'=>NULL, item1=>$model->id_item1, 'id_tablaA'=>model->ID,);
$this->_tablaB->save();
$this->redirect(array('view','id'=>$model->iD));
}
$this->render('create',array( 'model'=>$model, ));
}
What I’m doing wrong? Any help is appreciated