MasOud MasOud - 2 years ago 132
PHP Question

Calling a model in a Helper file using codeigniter

I want to write a function for loading dropdown in helper file and for that reason I want to Use my models in Helper file.

When I use this it give me the error:


The Error:

Fatal error: Using $this when not in object context in C:\xampp\test\application\helpers\component_helper.php on line 6

my method:

function dropdown($Class,$Attribute)
foreach ($FullData as $Data)
$Output.='<option value="'.$Data->Id.'">'.$Data->$Attribute.'</option>';
return $Output;


Answer Source

Check this post:

function my_helper()
    // Get a reference to the controller object
    $CI = get_instance();

    // You may need to load the model if it hasn't been pre-loaded

    // Call a function of the model

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download