Yii Framework不保存字段到DB的值

时间:2014-04-23 15:57:39

标签: php yii

我是PHP的新手,我正在开发一个使用Yii框架的项目。我在数据库中添加了一个新字段,由于某种原因它没有传递给数据库。

ALTER TABLE profiles
ADD organization_id INT(10);

我改变了验证,我认为这是包含该字段的问题。

public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will 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 already exists.'),
            array('participant_list_name', 'length', 'max'=>64),
            array('participant_list_desc', 'length', 'max'=>255),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('participant_list_id, organization_id, participant_list_name, participant_list_desc', 'safe', 'on'=>'search'),
            array('input_type','safe'),
    );
}

我使用以下内容将其包含在页面上的表单中:

<?php echo $form->hiddenField($model,'organization_id',array('value'=>Yii::app()->getModule('user')->user()->profile->organization_id)); ?>

呈现为:

<input value="1" name="ParticipantList[organization_id]" id="ParticipantList_organization_id" type="hidden">

显然我有些遗漏,但我不确定它是什么。我在数据库中使字段“not null”,并且我收到错误,说插入失败,因为organization_id需要一个值。

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。有人更改了被调用的方法,并替换了$ model-&gt; attributes = $ _ POST ['ParticipantList'];使用$ model-&gt; participant_list_name =($ _ POST ['ParticipantList'] ['participant_list_name']);所以它忽略了所有其他领域。目前我们无法添加所有属性,因为它导致它保存了一些正在验证的嵌套数据,因此我明确添加了组织ID。