php - 设置不安全属性失败

标签 php yii

您好,我在插入和更新操作时在日志中有警告字符串

2013/02/05 16:43:57 [warning] [application] Failed to set unsafe attribute "logo" of "Model".

模型规则

public function rules()
{
    return array(
        array('typeId, cityId, new', 'numerical', 'integerOnly'=>true),
        array('title, url', 'length', 'max'=>255),
        array('content, created, deleted', 'safe'),

        array('url', 'url', 'on'=>'insert, update'),

        array('typeId, cityId, title', 'required', 'on'=>'insert, update'),

        array('logo', 'file', 'types'=>'jpg, jpeg, gif, png', 'maxSize'=>100*1024, 'allowEmpty'=>true, 'tooLarge'=>'{attribute} is too large to be uploaded. Maximum size is 100kB.'),

        array('id, typeId, cityId, title, content, new, url, logo', 'safe', 'on'=>'search'),
    );
}

我不明白为什么我会这样磨损。我有 Logo 字段的规则并为其设置了 allowEmpty 选项

最佳答案

CFileValidator默认情况下是不安全的,来自 docs :

safe property (available since v1.1.12) public boolean $safe;

whether attributes listed with this validator should be considered safe for massive assignment. For this validator it defaults to false.

因此将safe属性设置为true

array('logo', 'file', 'types'=>'jpg, jpeg, gif, png','safe'=>true, 'maxSize'=>100*1024, 'allowEmpty'=>true, 'tooLarge'=>'{attribute} is too large to be uploaded. Maximum size is 100kB.'),

关于php - 设置不安全属性失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14709145/

相关文章:

yii - 从 CDbCriteria 获取字符串表示

php - 缓存index.php页面的搜索引擎有siteController但在yii PHP中没有模型

php - 如何在操作期间使用 php/yii 锁定表

php - 在所有 Yii View 中都有一个可用的变量

php - 使用 mysql php pdo 从数据库返回一个值

php - 学说查询 WHERE IN - 多对多

php - Laravel 删除和更新

PHP mail() 函数返回 true 但没有消息

javascript - 使用 jQuery 根据动态单选输入属性值更改总输入值

layout - 如何在 yii 中将数组从 Controller 发送到布局 header ?