Yii Framework Forum: Failed to set unsafe attribute "file" - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Failed to set unsafe attribute "file" how do I define file as safe attribute if my model does not have one Rate Topic: -----

#1 User is offline   maxlight 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 12-November 11

Posted 04 December 2011 - 03:40 PM

How do I define file as safe attribute if my model does not have a file attribute

I have a model where I store a name of a file which I upload using same models form.

inside form:
...
<div class="row">
	<?php echo CHtml::error($model, 'file')?>
	<?php echo CHtml::activeFileField($model, 'file')?>
</div>
...


I get this error inside my application log:

[warning] [application] Failed to set unsafe attribute "file" of "Carpics".

Can I make file safe at all if its not part of my model?

so how can I avoid that error?
0

#2 User is offline   jellysandwich 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 03-May 11

Posted 04 December 2011 - 08:26 PM

Why is it not part of your model? Just add it in...
0

#3 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 05 December 2011 - 12:55 AM

Pls, check wiki page about file uploading:
http://www.yiiframework.com/wiki/2/
0

#4 User is offline   Leo Tsai 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-February 12

Posted 10 December 2012 - 02:43 AM

In your Model, you can set the "safe" be true.
like above.

public function rules() {
return array(
array('file', 'file', 'types'=>'zip', 'safe'=>true),
);
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users