labelEx ans i18n

Hi,

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

                $this->performAjaxValidation($model);

                

		if(isset($_POST['ContactForm']))

		{

			$model->attributes=$_POST['ContactForm'];


                        

                        

			if($model->validate())

			{

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

				mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);

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

				$this->refresh();

			}

		}

                $model->attributeLabels(Yii::t('strings','name'));

                

		$this->render('contact',array('model'=>$model));

	}

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

thanks

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