attributeTitles like attributeLabels for input title attribute

Is there a way to create a function like attributeLabels with this behaviour:



<?php


public function attributeTitles()


	{


		return array(


                    'inputName1' => 'This is the title of the inputName1 to be used for tooltips'


		);


	}

If I put this function in every model php page, how can I say to Yii to use it for input title creation?

up :)

You have to implant this functionality yourself - it is not native to Yii.  There are many ways to do this.  This is very customized code you are asking for

Here's what I did:

  1. create method attributeHelp() in my models


class MyTable extends MyActiveRecord


...


	public function attributeHelp()


	{


          return array ('field1' => 'helptext for field 1',


                            'field2' => 'helptext for field f2',


                            etc.


                           )


        }


  1. extend CActiveRecord, add getter for the HelpText


class MyActiveRecord extends CActiveRecord


{


	public function getAttributeHelp($attribute)


	{


		$help=$this->attributeHelp();


		if(isset($help[$attribute]))


			return yii::t('MyApp',$help[$attribute]);


	}


}


  1. extend CHtml to automatically add tooltips (as Title attribute) to activeLabelEx()


class MyHtml extends CHtml


{


	public static function activeLabelEx($model,$attribute,$htmlOptions=array())


	{


		$realAttribute=$attribute;


		self::resolveName($model,$attribute); // strip off square brackets if any


		$htmlOptions['required']=$model->isAttributeRequired($attribute,self::$scenario);


		$htmlOptions['title']=$model->getAttributeHelp($attribute); // + JJD


		return self::activeLabel($model,$realAttribute,$htmlOptions);


	}


}


  1. use MyHtml::activeLabelEx() in my views
  • jeremy

It’s a good idea to implement on Yii 1.1 ;)