Yii Framework Forum: Add Title For Label In Model - Yii Framework Forum

Jump to content

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

Add Title For Label In Model Add title for label in model Rate Topic: -----

#1 User is offline   speaki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 06-April 12

Posted 13 December 2013 - 05:56 AM

Often you want to give the user info about inputfields, you never no when the user want the information so i want to give the user information via the title attribute on every label.

One way to this is like:
<?php echo $form->labelEx($model,'extra',array('title'=>'Info to user...')); ?>        

But then you have to write it all over for each label. I would to have the titel attribute like attributeLabels in model. Or even better, have default htmlOptions per column, like:

In model:
public function htmlOptions()
{
	return array(
		'id' => array('title'=>''),
		'extra' => array('title'=>'In this field...'),
		...
	);
)


Its possibel to build this logik in the framework but i dont want to change the framworks files.

Any ideas/experience?
0

#2 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 384
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 14 December 2013 - 03:03 AM

yes possible you can create it as a model's method or separate component. the decision is depending upon u
My Blog - Yii Learner
0

#3 User is offline   speaki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 06-April 12

Posted 18 December 2013 - 01:59 PM

View PostAhamed Rifaideen, on 14 December 2013 - 03:03 AM, said:

yes possible you can create it as a model's method or separate component. the decision is depending upon u



model's method? widthout changing in the framwork? how?
0

#4 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 384
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 18 December 2013 - 07:53 PM

View Postspeaki, on 18 December 2013 - 01:59 PM, said:

model's method? widthout changing in the framwork? how?

write some method in the model like as you posted in the previous post and call that method in your view like this
$model->someMethod()

My Blog - Yii Learner
0

#5 User is offline   speaki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 06-April 12

Posted 19 December 2013 - 09:47 AM

View PostAhamed Rifaideen, on 18 December 2013 - 07:53 PM, said:

write some method in the model like as you posted in the previous post and call that method in your view like this
$model->someMethod()




But the ide is to make no call. The title should be shown even if i dont write any title, or any htmlOptions.
0

#6 User is offline   explorer 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 26-July 13

Posted 19 December 2013 - 11:36 PM

My idea is to extend the form class, eg. CActiveForm, extend this class and override the label and labelEx methods:
class ActiveForm extends CActiveForm
{
   public function label($model,$attribute,$htmlOptions=array())
   {
     if (method_exists($model, 'attributeHtmlOptions')) 
     {
       $arrHtmlOptions = $model->attributeHtmlOptions();
       if (isset($arrHtmlOptions[$attribute]))
         $htmlOptions = $arrHtmlOptions[$attribute];
     }

     return CHtml::activeLabel($model,$attribute,$htmlOptions);
   }
}


Then you can write attributeHtmlOptions method in your model like you said in your first post, and in the view you use ActiveForm widget instead of CActiveForm.
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