Yii - 不能为表单提交定义一个安全的属性数组


Yii - cannot define a safe array of attributes for form submit

我有一个PHP表单,需要提交一个数字数组,我们的观点是:

<input type="text" id="ProductForm_sizeobj_1" name="ProductForm[sizeobj[1]]" value="13">
<input type="text" id="ProductForm_sizeobj_2" name="ProductForm[sizeobj[2]]" value="13">
<input type="text" id="ProductForm_sizeobj_3" name="ProductForm[sizeobj[3]]" value="13">

我在表单类中定义:

public $sizeobj = array();
public function rules() {
    return array(
        array('/** other attributes **/, sizeobj', 'safe')
    );
}

由于"Sizeobj"是一个动态属性,并且大小将增长超过3,因此我使用数组。但是,在表单提交后,错误抛出如下:

Failed to set unsafe attribute "sizeobj[1" of "ProductForm".

我相信我可能使用错误的方法设置数组属性或错误的规则,有什么建议吗?我是Yii的新手,任何帮助都值得赞赏。

使用 name="ProductForm[sizeobj][1]" 而不是 name="ProductForm[sizeobj[1]]"

相关文章: