嗨我在插入和更新操作时在日志中有警告字符串
2013/02/05 16:43:57 [warning] [application] Failed to set unsafe attribute "logo" of "Model".
Run Code Online (Sandbox Code Playgroud)
模型规则
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'),
);
}
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么我会这样做.我有徽标字段的规则,并有allowEmpty选项
Asg*_*oth 16
默认情况下,CFileValidator不安全,来自文档:
安全属性(自v1.1.12起可用)public boolean $ safe;
是否应将此验证器列出的属性视为大规模分配的安全性.对于此验证器,它默认为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.'),
Run Code Online (Sandbox Code Playgroud)