0

iam using cakephp model validation. i want to display some validation error message in the model class

    var $validate = array(

    'name' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Please Enter a Group Name',
            ),
        'unique' => array(
            'rule'    => 'isUnique',
            'message' => 'This Group Name is already exist'
        ));

i wrote the above sentence. it works fine. but i want to declare these messages globally. how to do this?. if anybody kow this please help me.

SibinF
  • 385
  • 1
  • 7
  • 25
  • Globally meaning accessible to models, to controllers or something else? – skywalker Mar 14 '14 at 08:37
  • @skywalker i want to access it from anywher from model.controller,and view. any solution is there? – SibinF Mar 14 '14 at 10:32
  • @skywalker i want to access it from all controller,model and view – SibinF Mar 14 '14 at 10:33
  • Why do you need validation messages in your controller and view? – skywalker Mar 14 '14 at 12:53
  • @SibinF Read about the MVC pattern, what you plan to do violates it and works *against* the framework. In other words: What you want to do is wrong. – floriank Mar 14 '14 at 13:24
  • @skywalker No No... i didnt think about it.. see what i am telling is i have a model class, controller class,and view. i want o display some information in these three classes so i want to write only one time that can be use in these three classes. correct? is there any way for that declaring variables that are available in both controller,model and view file. – SibinF Mar 14 '14 at 14:14
  • 1
    As @burzum said, that is wrong, don't do that. Rethink everything and try different approach. – skywalker Mar 14 '14 at 14:18

1 Answers1

0

To achieve the same objective, just use the error global message in the View file instead of the Model file.

echo $form->input('login', array(
'label' => __('Login', true),
'error' => array(
        'loginRule-1' => __('Only alphabets and numbers allowed', true),
        'loginRule-2' => __('Minimum length of 8 characters', true)
    )
));

Reference: http://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Data-Validation.html

*just before the "Core Validation Rules" section

Note: The validation message in the Model file only accepts text values.

Asenara
  • 1
  • 1