Apr 1, 2011

About error messages and locales

Localization
1. create file for localization
/protected/messages/
/en/default.php
/cn/default.php
/jp/default.php

2. specific a lang
Yii::app()->language = "en"
: this means your en folder under /protected/messages.

3. in your default.php, write things as follows,

return array(
'name' => 'xing ming',
'required' => 'bu neng wei kong',
);
?>

4. anywhere you want to use the localized name, write,
Yii::t('default', 'name');

custum error message.
1. in your model/Model.php, find function rules.
return array(
array('name, mail', 'required', 'message' => Yii::t('default', 'required'); ),
);

2. This tag will show all the form errors in a block.
The second param is the title of the block.
Here I leave it blank.
errorSummary($model, ""); ?>



No comments:

Post a Comment