How to create the custom Drop-down using CHtml::dropDownList

You are viewing revision #3 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#2)next (#4) »

Hi Friends, This tutorial may be help us create the custom drop-down menu using CHtml::dropDownList

1) first create/copy the drop-down menu in your _form.php file

<div class="control-group">
<label class="control-label"><?php echo $form->labelEx($model,'dob'); ?></label>
<div class="controls">
<?php  echo CHtml::dropDownList('VkUsers[month]', '', UtilityHtml::getMonthsArray());?>
<?php  echo CHtml::dropDownList('VkUsers[day]', '', UtilityHtml::getDaysArray());?>
<?php  echo CHtml::dropDownList('VkUsers[year]', '', UtilityHtml::getYearsArray());?>
</div>
</div>

2) Create the UtilityHtml.php file on componets folder which is include a all html file function

/**
	 * @Method		  : Dynemic Month
	 * @Params		  :
	 * @author        : Ankit Modi
	 * @created		  :	JULY 11 2014
	 * @Modified by	  :
	 * @modified	  :
	 * @Comment		  : Dynemic Month
	 */
	public static function getMonthsArray()
	{
		for($monthNum = 1; $monthNum <= 12; $monthNum++){
			$months[$monthNum] = date('F', mktime(0, 0, 0, $monthNum, 1));
		}

		return array(0 => 'Month:') + $months;
	}

	/**
	 * @Method		  : Dynemic Days
	 * @Params		  :
	 * @author        : Ankit Modi
	 * @created		  :	JULY 11 2014
	 * @Modified by	  :
	 * @modified	  :
	 * @Comment		  : Dynemic Days
	 */
	public static function getDaysArray()
	{
		for($dayNum = 1; $dayNum <= 31; $dayNum++){
			$days[$dayNum] = $dayNum;
		}

		return array(0 => 'Day:') + $days;
	}

	/**
	 * @Method		  : Dynemic Years
	 * @Params		  :
	 * @author        : Ankit Modi
	 * @created		  :	JULY 11 2014
	 * @Modified by	  :
	 * @modified	  :
	 * @Comment		  : Dynemic Years
	 */
	public static function getYearsArray()
	{
		$thisYear = date('Y', time());

		for($yearNum = $thisYear; $yearNum >= 1920; $yearNum--){
			$years[$yearNum] = $yearNum;
		}

		return array(0 => 'Year:') + $years;
	}

0 0
3 followers
Viewed: 28 346 times
Version: Unknown (update)
Category: How-tos
Written by: Ankit Modi
Last updated by: samdark
Created on: Jul 15, 2014
Last updated: 6 years ago
Update Article

Revisions

View all history

Related Articles