This error happens to me when I do try to render $b misstyping the object’s some property and concatenating to a string ( ie. echo $b , echo ‘some string’.$b ) can we see the actual code?
ModelA can have Many ModelBs but there relation is saved in ABRelationshipModel. so there is none of ModelA’s primary key is saved in ModelB as foreign key.
ModelA’s and ModelB’s, primary key of both is saved in ABRelationshipModel.
There is direct relation ship between ModelB and ModelC. and these are the models in my actual question, giving me the problem
public function actionCreate()
{
$model=new ModelB;
$modelABR = new ABRelationshipModel;
$modelC = new ModelC;
//we need to save the modelA and ModelB RelationShip
//_a_Obj is filled by the filterAContext to ensure right A model
// is loaded before the ModelB is created
$modelABR->a_id = $this->_aObj->a_id;
$a_id = $modelABR->a_id;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['ModelB'], $_POST['ModelC']))
{
$model->attributes=$_POST['ModelB'];
$model->changed = new CDbExpression('NOW()');
$modelC->attributes = $_POST['ModelC'];
if($model->save())
{
$modelABR->ModelB_id = $model->ModelB_id;
$modelC->ModelB_id = $model->ModelB_id;
$flag = true;
if( $modelABR->save())
{
if( !$modelC->save())
{
$modelABR->delete();
$model->delete();
$flag = false;
}
}
else
{
$flag = false;
$model->delete();
}
if ($flag == true)
{
$this->redirect(
array('view', 'q_id'=>$a_id,
'id'=>$model->ModelB_id));
}
}
}
$this->render('create',array(
'model'=>$model,
'modelC'=>$modelC,
));
}
Why dont you set the $b to null if A is not validated and check that value against null on your view? This way a value is passed and then on the view? As I think the problem arises there.