Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to set unsafe attribute

Tags:

php

yii

Hi i have warning string in log while insert and update action

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

Rules for 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'),
    );
}

I can't understand why I get this worning. I have rule for logo field and have allowEmpty option for it

like image 480
dr0zd Avatar asked Feb 05 '13 13:02

dr0zd


1 Answers

CFileValidator is by default unsafe, from the 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.

So set safe attribute to 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.'),
like image 71
Asgaroth Avatar answered Sep 18 '22 12:09

Asgaroth