[eluser]helmutbjorg[/eluser]
Okay... I guess your code looks awfully complicated for a relatively simple process.
You don't really need to extend the model to do all this. Put Phils function into a general helper perhaps with a boolean option of whether to include a blank option at the start.
Code:
function array_to_select($results, $value = 'id', $key = 'title', $add_blank=false)
{
// Converts objects to arrays
if(is_object($results)) $results = get_object_vars($results);
$options = array();
if(!empty($add_blank)) $options = array(null=>$add_blank);
// Will only run if results is an array, not a string, int, etc.
if(is_array($results))
{
foreach($results as $result)
{
// Get the two rows specified
$options[$result[$value]] = $result[$key];
}
}
return $options;
}
Usage
Code:
$options = array_to_select($result, 'company_id', 'company_name', '--');
$company_list = form_dropdown('contact_company', $options, '', $attributes);
This way you can re-use the code in the future. This is not tested it is just to give you the idea.