I have 5 fields in a model 3 of which I am capturing in _form and rest of the 2 are being set in beforeSave() method. In controller, when I do the following, it doesn’t assign all 3 variables to $model->attributes even though field names, database column names are same.
$model->attributes = $_POST['Model'];
One thing I noticed is that it’s assigning text items properly however not assigning numeric fields. In my case, there is on text field and 2 integer fields. I have verified that all values are coming properly in $_POST but when it’s assigned to $model->attributes then integer values are not saved in model.
Any ideas why this could be happening? As of now, I am manually assigning those integer fields from $_POST values but that doesn’t seem the right way of doing it.
Here is the controller code. parent_id and story_id are not been assigned when I am assigning $_POST to model attributes, comment is being assigned properly.
public function actionCreate()
{
$model=new Comment;
if(isset($_POST['Comment']))
{
$model->attributes=$_POST['Comment'];
if($model->save())
$this->redirect(array('story/view','id'=>$model->attributes['story_id']));
}
}