Add A Custom Message To Validation Rule

I have the following rules in my model. The problem is that the custom error message is not displaying. Instead, the default message is displaying. Any idea why that is? I appreciate any help.




    public function rules() {

        return array(

            array('quantity', 'safe'),

            array('quantity', 'required'),

            array('quantity', 'numerical', 'min'=>1, 'message'=>'{attribute} must be greater than zero.')

        );

    }

change it to


   public function rules() {

        return array(

            array('quantity', 'safe'),

            array('quantity', 'required'),

            array('quantity', 'numerical', 'message'=>'{attribute} must be greater than zero.')

        );

    }

How do I specify the minimum?

use the length validation rule for that

array(‘name’, ‘length’, ‘min’=>2),

I want to specify a minimum for a numerical field AND display a custom error message when that minimum is not met. How do I do that?

You did even bother to look at the code.

try this


public function rules() {

        return array(

            array('quantity', 'safe'),

            array('quantity', 'required'),

            array('quantity', 'numerical')

            array('quantity', 'length', 'min'=>2, 'message'=>'{attribute} must be greater than zero.')

        );

    }


    public function rules() {

        return array(

            array('quantity', 'numerical', 'min'=>'1', 'tooSmall'=>'{attribute} must be greater than zero.'),

            array('quantity', 'required'),

            // array('quantity', 'safe'), <- this is not needed unless on a specific scenario, like 'search'

        );

    }

http://www.yiiframework.com/wiki/56/#hh16

http://www.yiiframework.com/doc/api/1.1/CNumberValidator

I looked up the documentation for CNumberValidator, and the property that should be set is "tooSmall" instead of "message". The following code solved my problem:


    public function rules() {

        return array(

            array('quantity', 'safe'),

            array('quantity', 'required'),

            array('quantity', 'numerical', 'min'=>1, 'tooSmall'=>'{attribute} must be greater than zero.')

        );

    }

http://www.yiiframework.com/doc/api/1.1/CNumberValidator

Edit: Thanks bennouna. I just saw your reply.