Add A Prefix Before Each Dropdownlist Element

Hello,

I would like to add a prefix before all my dropdownlist element. For example, I generate a dropdownlist which gives me all addresses of all my servers written in a table, however I would like for visibility add "http://" before each address in my drop down list.

Have you an idea ?

thanks

You can add a method in your model like this:-




	 public function getXXX()

	 {

	 	return 'http://'.$this->server_address;

	 }




And then add in your view for your dropdownlist, for example:-





<?php echo $form->dropDownList($model,'yourtable',

 		CHtml::listData(Yourtable::model()->findAll(), 'yourtable_id', 'XXX'),array('prompt' => 'Select')); ?>



You can use own method extend default CHtml::listData($model,"key","value");




	public static function listDataWithPrefix($models,$valueField,$textField,$groupField='',$prefix = "")

	{

		$listData=array();

		if($groupField==='')

		{

			foreach($models as $model)

			{

				$value=self::value($model,$valueField);

				$text=$prefix . self::value($model,$textField);

				$listData[$value]=$text;

			}

		}

		else

		{

			foreach($models as $model)

			{

				$group=self::value($model,$groupField);

				$value=self::value($model,$valueField);

				$text=$prefix . self::value($model,$textField);

				$listData[$group][$value]=$text;

			}

		}

		return $listData;

	}



hmmm ok, thanks you both, I thought there would be an html option to put in chtml::dropdownlist to do it, but apparently not.