gpt4 book ai didi

php - 是什么导致 $model->attributes 在 Yii 中得不到正确的值?

转载 作者:可可西里 更新时间:2023-11-01 00:00:50 37 4
gpt4 key购买 nike

我的 actionCreate 中有这些行:

if (isset($_POST['DpcioCbn'])) {
print_r($_POST['DpcioCbn']);
$model->attributes = $_POST['DpcioCbn'];
print_r($model->attributes);
die();
...
}

返回这个:

Array
(
[code] => 34324
[bn_fa] => dfsf
[bn_en] => sdf
[cbn_fa] => sdfds
[cbn_en] => f
[description] => dsfsdfsdf
[update_at] => 1391-03-16
[active] => 1
)
Array
(
[active] => 1
[code] => 34324
[bn_fa] => dfsf
[bn_en] => sdf
[cbn_fa] => sdfds
[cbn_en] => f
[update_at] => 1391-03-16
[id] =>
[description] =>
)

description 字段会发生什么? Yii 有什么关于这个任务的吗?

最佳答案

我发现在 yii 中有一个关于这种类型分配的术语:Massive Assignment。所以我应该为每个字段明确定义验证以进行 Massive Assignment。

public function rules() {
return array(
...
array('description', 'safe'),
...
);
}

http://www.yiiframework.com/wiki/161/understanding-safe-validation-rules/#hh2

For some fields, there's nothing to validate, right?

Wrong: by only assigning field values that the user has explicitly said are eligible for copying into $model, this limits shenanigans of a bad guy trying to pollute a model.

Even if a field has no particular data-format validations, we still have to tell Yii we want the attribute copied during Massive Assignment. This is done with the 'safe' validator.

关于php - 是什么导致 $model->attributes 在 Yii 中得不到正确的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11086436/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com