Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Cmodel->Adderror() Attribute Label In Message

$
0
0
Hi
I have some model with custom validation rule

    public function rules()
    {
        return array(
             ...
             array('role_id', 'exist', 'attributeName'=>'id', 'className'=>'UserRole', 'message'=>'Select {attribute}!'),
             array('mail', 'someFunction'),
             ...
        );
    }

    public function attributeLabels()
    {
        return array(
            ...
            'mail' => 'E-mail',
            'role' => 'User role',
            ...
        );
    }

    public function someFunction($attribute,$params)
    {
        if(!$this->hasErrors())
        {
            .....

            if(....)
            {
                $this->addError('mail','{attribute} ...!');
            }
            elseif()
            {
                $this->addError('mail','....{attribute} ...!');
            }

        }
    }

When model can not be validated by role_id field rule, I get message 'Select User role!'
But if model can not be validated by mail filed, I get messages like '{attribute} ...!'

So I want to get {attribute} substituted by attribute label, but it is not substituted. Why?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>