Why can’t I call methods directly on my object in CodeIgniter?
For example:
$campaign = $this->Campaign_model->get_campaign_from_id($campaign_id);
$campaign->load_settings(); // returns error: Call to undefined method stdClass::load_settings()
The Campaign object is correctly created, but I can’t call methods on it even if it’s within the class.
Here is my Campaign_model method I’m calling:
function load_settings()
{
echo "test";
exit;
}
How can I do this kind of operations then? I think I was respecting basic object logic, but I can’t make it work.
CodeIgniter models are just a collection of functions, there is only ever one instance of each model. You don’t return “model objects”, that’s not how it works.
The “object” you are returning from
get_campaign_from_idis just a normal PHP object and has nothing to do with your model.You can’t call functions on
stdClassobjects, but you can pass it to a function that can edit its properties.