Yii Framework Forum: Custom Message And Safe Questions - Yii Framework Forum

Jump to content

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

Custom Message And Safe Questions rules() Rate Topic: -----

#1 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 11 February 2013 - 10:36 PM

1) I can't get {attribute} in custom message to work. It always shows as is. Here's a snippet:
array('crew_code', 'exist', 'attributeName'=>'crew_code', 'className'=>'Crew', 'message'=>'crew {crew_code} does not exist'),

the following will display an error upon invalid data, but {crew_code} doesn't convert to attribute's value, it just shows {crew_code} in the message. What am I doing wrong here?

2) What does "safe" really mean in rules? I see in the docs it says it's safe for mass assign, but not really sure I understand. Is it the same as leaving an attribute out of rules completely, what's the difference? And I take it since Yii uses PDO, I should have no concern in regards to injections, right?

Sorry, lots of questions, I'm very new to Yii.
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 12 February 2013 - 01:16 AM

Dear Friend

1.{attribute} is the standard placeholder for all validator class.
It only represents the attribute label and not the actual value.
for CExistValidator an additional placeholder {value} is available. You should try that.

It should be
'message'=>"crew {attribute} does not exist",


or

'message'=>"crew {value} does not exist",


or

'message'=>"crew {attribute} having a value of {value} does not exist",


2.For an attribute to get involved in massive assigment, we should have at least one rule imposed on it.
If there is no rules declared for that attribute, we should declare it safe at least.

Regards.
0

#3 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 12 February 2013 - 09:30 AM

Thank you, these explanations help.
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