Rules and messages

I want write all text of message that I use in function rules, save in a file. How is better do this? ِDo I must write a function in components or …?


	

public function rules()

{

return array(

  array('age', 'numerical', 'integerOnly'=>true,'message'=>'My text My text My text My text'),

            );

}

Create an application component, for example ErrorMessagesComponent, to call with:

Yii::$app->errorMessageCompoennt->writeMessage($codeMessage)

where $codeMessage could be "err1", "err2" or what you want.

You can use a translation’s file (see http://www.yiiframework.com/doc/guide/1.1/en/topics.i18n#translation)


public function rules()

{

return array(

  array('age', 'numerical', 'integerOnly'=>true,'message'=>Yii::t('app', 'message x')),

            );

}

in your "message/en/app":


<?php


return array(

    'message x' => 'My text My text My text My text',

);