Yii Framework Forum: Question about safeAttributes - Yii Framework Forum

Jump to content

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

Question about safeAttributes is safeAttributes required? Rate Topic: -----

#1 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 248
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 29 October 2009 - 10:39 AM

Hi I'm going through the blog tutorial 1.1a

on page 17 a method called safeAttributes is discussed the text tells me to modify this method (but it is not created by yiic)

Do I have to create a method called safeAttributes like this
    public function safeAttributes()
    {
        return array('ismenu','ispublished','isvisible','iscontainer');
    }


or is this line doing exactly the same thing?
array('ismenu, ispublished, isvisible, iscontainer', 'safe'),


in this yiic generated method
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, linktext, linkurl, description, acl', 'required'),
			array('title', 'required','message'=>'Custom message for title'), // my mod
			array('linkindex, acl', 'numerical', 'integerOnly'=>true),
			array('name, menu, pageparent', 'length', 'max'=>50),
			array('linktext', 'length', 'max'=>30),
			array('linkurl', 'length', 'max'=>200),
			array('description, title', 'length', 'max'=>160),
			array('ismenu, ispublished, isvisible, iscontainer', 'safe'),
		);
	}
 


Is it possible the blog demo is out of date regarding this?
doodle
Check out myYii powered website
0

#2 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 29 October 2009 - 10:59 AM

yii 1.1 has no longer the safeAttributes() method. just make sure the attribute has a validation rule (rules()). attributes that don't need a validation rule just assign safe to them. see Email and Priority.

see also http://www.yiiframew...model-scenarios

    public function rules()
    {
        return array(            
            array('CityId, Daytrip, Street, Number, ZipCode, Website, Categories, Tags, Active', 'required'),
            array('Email, Priority', 'safe'),
        );
    }

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