php - Yii Framework not saving value for field to DB -
i new php, , working on project uses yii framework. have added new field our database, , reason isn't being passed database.
alter table profiles add organization_id int(10);
i altered validation, thought issue include field.
public function rules() { // note: should define rules attributes // receive user inputs. return array( array('participant_list_id, organization_id', 'numerical', 'integeronly'=>true), array('participant_list_name, organization_id', 'required'), array('participant_list_name', 'unique', 'message' => 'the name exists.'), array('participant_list_name', 'length', 'max'=>64), array('participant_list_desc', 'length', 'max'=>255), // following rule used search(). // @todo please remove attributes should not searched. array('participant_list_id, organization_id, participant_list_name, participant_list_desc', 'safe', 'on'=>'search'), array('input_type','safe'), ); }
i included in form on page using following:
<?php echo $form->hiddenfield($model,'organization_id',array('value'=>yii::app()->getmodule('user')->user()->profile->organization_id)); ?>
which renders as:
<input value="1" name="participantlist[organization_id]" id="participantlist_organization_id" type="hidden">
clearly there missing, not sure be. made field "not null" in db, , error saying insert failed, because organization_id requires value.
i discovered issue. changed method being called, , replaced $model->attributes=$_post['participantlist']; $model->participant_list_name=($_post['participantlist']['participant_list_name']); ignoring other fields. stands weren't able add attributes, because caused save nested data being validated, explicitly added org id.
Comments
Post a Comment