labelEx ans i18n


When you have a form with a required field, you have this:

<?php echo $form->labelEx($model,'email'); ?>

and you have the "*" near the word.

Now, i internationalize the form. So, now i have :

<?php echo $form->labelEx($model,Yii::t('strings','email')); ?>

and i lost the "*" near the word !

How to keep it ?

thanks :D

Note that the second parameter to labelEx should be the attribute name… so you need to leave here ‘email’

If you want to internationalize the label… you set that in the model->attributeLabels()… there you can use t(…)

For exemple, if i work on the contact form :

public function actionContact()


                $baseUrl = Yii::app()->theme->baseUrl;

                Yii::app()->getClientScript()->registerScriptFile("{$baseUrl}/js/winetkr.js", CClientScript::POS_HEAD);

		$model=new ContactForm;

                // Uncomment the following line if AJAX validation is needed










				$headers="From: {$model->email}\r\nReply-To: {$model->email}";


				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');








it doesn’t work…i thanks a don’t know how to use attributeLabels, have you an exemple ?


The attributeLabel() method is in the model… the model for the contact form (if you use Yiic generated code) is in protected/model/ContactForm.php

Perfect, excuse me… :unsure:

public function attributeLabels()


		return array(

			'verifyCode'=>'Verification Code',

                        'name' =>(Yii::t('strings','Name')),



thanks a lot