Yii Framework Forum: form label problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

form label problem Rate Topic: -----

#1 User is offline   Bent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 29-October 10

  Posted 29 October 2010 - 07:14 AM

My problem is using:


In my view:
<?php echo $form->labelEx($model,'henkilötunnus'); ?>
<?php echo $form->textField($model,'ht',array('size'=>20,'maxlength'=>11)); ?>


in my model:
I have
public $ht;


and in rules:
array('fname, lname, ht', 'required'),


I would like to have the form input fields name to be different than the label (what the user sees). This site is in Finnish so Henkilötunnus is what I want to be displayed and I would like to have "ht" to be the name of the text input. For some reason Henkilötunnus is displayed as: Henkil�tunnus so the ö is not displayed correctly and I'm sure this applies to all special characters that are used in label. I know I can do a workarround and not do the $form->labelEx($model,'henkilötunnus'); part. But just want to know what is the "correct" way to do this now before I start by doing things the "wrong" way.

I'm totally new to Frameworks and Yii but I've done a lot with php and template engines.
I do understand MVC but I've never developed anything using this method.
I'm using Yii 1.1.4 and the example site that came with it as a starting point for a test application I'm making to see if Yii would be a good way for us to make web apps from now on.

Any help would be appreciated.
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 29 October 2010 - 07:16 AM

In the model there is a function AttributeLabel, wich is used for specify the label of each field of the database.
0

#3 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 29 October 2010 - 09:45 AM

         /**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'T&iacute;tulo',
			'description' => 'Descripci&oacute;n'; // fieldname=>spanish :)
		);
	}


Then on your view:


<?php echo CHtml::activeLabel($model,'title'); // will display T&iacute;tulo appropiately ?> 


¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#4 User is offline   Bent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 29-October 10

Posted 01 November 2010 - 03:41 AM

View PostAntonio Ramirez, on 29 October 2010 - 09:45 AM, said:

         /**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'T&iacute;tulo',
			'description' => 'Descripci&oacute;n'; // fieldname=>spanish :)
		);
	}


Then on your view:


<?php echo CHtml::activeLabel($model,'title'); // will display T&iacute;tulo appropiately ?> 





Thanks a lot this solved it for me.
0

#5 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 01 November 2010 - 04:20 AM

Great it worked out for you..
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users