Hi all,
How to save data twice into a single table with different values each time based on a if condition?
Hi all,
How to save data twice into a single table with different values each time based on a if condition?
hi sravani,
If you are trying to enter same data twice then use afterSave() method and automatically insert the data based on the condition.
for example if you have student table with fields id,name,marks,result.
then for the first time you enter (1,abc,25) result you left empty .
in the model class
protected function afterSave()
{
parent::afterSave();
if($this->marks < 25)
{
$stud = new Student;
$stud->name= $this->name;
$stud->marks= $this->marks
$stud->result= 'pass';
}
else
....
}
if (!$stud->save()) {
echo "didn't work";
ii::app()->end(); // don't use die();
}
}