Welcome Guest, Not a member yet? Register   Sign In
call a model function in other file
#1

[eluser]Mitja[/eluser]
Why this is not working. I want to use it in view/admin/arrangement_edit.php

Code:
<tr>
<td>
Odhod:
<select name="departure_type">
&lt;?php echo $this->function_model->gkListArrayAsOptions($TransportTypesArray,  $row->departure_type); ?&gt;
</select>
</td>
</tr>

this is model/function_model.php file

Code:
class Function_model extends Model {

    function Function_model()
    {
        parent::Model();
    }
    
    function gkListArrayAsOptions($array, $selected=null)
    {
        $output = "";
    
        foreach($array as $value=>$text)
        {
            $selectAtt = "";
            if ($value == $selected) $selectAtt = "selected=\"selected\"";
            $output .= "<option value=\"$value\" $selectAtt>$text</option>";
        }
    
        return $output;
    }
}
#2

[eluser]Lone[/eluser]
First thing to check is does the function work within the controller that you loaded that view from?
#3

[eluser]Michael Wales[/eluser]
Without seeing the controller I'd say you probably have not loaded the model (the model must be loaded and the object instantiated - which CodeIgniter does for you - prior to using it).
Code:
$this->load->model('function_model');

We can get into the debate of calling a model from a view and how this should be a helper later. Tongue




Theme © iAndrew 2016 - Forum software by © MyBB