【问题标题】:Yii - cannot define a safe array of attributes for form submitYii - 无法为表单提交定义安全的属性数组
【发布时间】:2014-04-07 18:42:13
【问题描述】:

我有一个 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 的新手,感谢任何帮助。

【问题讨论】:

标签: php yii


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2017-05-08
    • 2016-08-25
    • 2020-10-26
    • 2020-07-15
    • 2021-07-06
    相关资源
    最近更新 更多