Created
May 20, 2011 13:15
-
-
Save codersatx/982864 to your computer and use it in GitHub Desktop.
Dropdown class used in Kohana to create dropdowns programatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Drop Down | |
* | |
* Enables easier creation of drop downs within our code. | |
*/ | |
class Dropdown{ | |
public $dd_open; | |
public $dd_options; | |
public $dd_close; | |
/** | |
* Constructor | |
* | |
* Sets up the class | |
* | |
* @access public | |
* @param array $params (prototype: array('key'=>'value,'key2'=>'value'); | |
* @return void | |
*/ | |
public function __construct($params) | |
{ | |
$this->dd_open = '<select id="'.$params['id'].'" name="'. $params['name'].'">'; | |
$this->dd_close = '</select>'; | |
} | |
// ------------------------------------------------------------------------ | |
/** | |
* Option | |
* | |
* Adds an option to our drop down list class member $dd_options | |
* | |
* @access public | |
* @param array $data (prototype: array('value'=>'...','title'=>'...',[optional 'selected'=>'selected']) | |
* @return void | |
*/ | |
public function option($data) | |
{ | |
if (isset($data['selected'])) | |
{ | |
$selected = 'selected="selected"'; | |
} | |
else | |
{ | |
$selected = ""; | |
} | |
$option = '<option value="'. $data['value'].'" '. $selected .'>'; | |
$option .= $data['title']; | |
$option .= '</option>'; | |
$this->dd_options .= $option; | |
} | |
// ------------------------------------------------------------------------ | |
/** | |
* Build | |
* | |
* Renders the final drop down list | |
* | |
* @access public | |
* @return string $dd | |
*/ | |
public function build() | |
{ | |
$dd = $this->dd_open; | |
$dd .= $this->dd_options; | |
$dd .= $this->dd_close; | |
return $dd; | |
} | |
} | |
/* End of file cf_drop_down.php */ | |
/* Location: ./application/libraries/cf_drop_down.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment