Created
January 5, 2013 08:00
-
-
Save jrmadsen67/4460432 to your computer and use it in GitHub Desktop.
A CodeIgniter dynamic dropdown to allow common languages to appear both at the top of the list and in order
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
function full_languages_dropdown($id='' ) | |
{ | |
$ci = &get_instance(); | |
$ci->load->model('language_model'); | |
$common_languages = $ci->language_model->order_by('language', 'asc')->get_many_by(array('common'=>1)); | |
$languages = $ci->language_model->order_by('language', 'asc')->dropdown('id', 'language'); | |
$html = '<select id="'.$id.'" name="'.$id.'">'; | |
if (!empty($common_languages)) | |
{ | |
foreach ($common_languages as $key => $common_language) { | |
$html .= '<option value="'. $common_language->id .'">'. $common_language->language .'</option>'; | |
} | |
//separator | |
$html .= '<option value=""> ------ </option>'; | |
} | |
if (!empty($languages)) | |
{ | |
foreach ($languages as $key => $language) { | |
$html .= '<option value="'. $key .'">'. $language .'</option>'; | |
} | |
} | |
$html .= '</select>'; | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment