Custom Message And Safe Questions

  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?

  1. 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.

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.

Thank you, these explanations help.