Question

I created a new model in OpenCart in a folder called catalog/model/donate/campaign.

<?php
class ModelDonateCampaign extends Model {
public function addCampaign($data) {
    $this->db->query("INSERT INTO `
        " . DB_PREFIX . "campaign`  
        SET campaign_name = '" . $this->db->escape($data['campaign_name']) 
        . "', campaign_description = '" . $this->db->escape(['campaign_description']) 
        . "', campaign_startdate = '" . $this->db->escape($data['campaign_startdate']) 
        . "', campaign_enddate = '" . $this->db->escape($data['campaign_startdate'])
        . " '")


    return $order_id;
}



}
?>

In my controller I have...;

$this->language->load('donate/campaign');
$this->model_donate_campaign->addCampaign($data);

the error Im receiving is for when I try to call the last function...

Fatal error: Call to a member function addCampaign() on a non-object in C:\xampp\htdocs\charity\catalog\controller\donate\newcampaign.php on line 21

Is there part of the procedure that Im missing for setting up a model?

Thank you

Was it helpful?

Solution

you need to first load model like

$this->load->model('donate/campaign');

then use

$this->model_donate_campaign->addCampaign($data);

and don't use $this->language->load('donate/campaign'); if you have not created language file that is catalog/language/donate/campaign.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top