0

Uncaught Error: Call to a member function preDemo1() on null in /opt/lampp/htdocs/epos/catalog/controller/prerecorded/preDemo.php:43 Stack trace: #0 /opt/lampp/htdocs/epos/system/engine/action.php(79): ControllerPrerecordedPreDemo->insertData() #1 /opt/lampp/htdocs/epos/catalog/controller/startup/router.php(25): Action->execute(Object(Registry)) #2 /opt/lampp/htdocs/epos/system/engine/action.php(79): ControllerStartupRouter->index() #3 /opt/lampp/htdocs/epos/system/engine/router.php(67): Action->execute(Object(Registry)) #4 /opt/lampp/htdocs/epos/system/engine/router.php(56): Router->execute(Object(Action)) #5 /opt/lampp/htdocs/epos/system/framework.php(168): Router->dispatch(Object(Action), Object(Action)) #6 /opt/lampp/htdocs/epos/system/startup.php(104): require_once('/opt/lampp/htdo...') #7 /opt/lampp/htdocs/epos/index.php(19): start('catalog') #8 {main} thrown in /opt/lampp/htdocs/epos/catalog/controller/prerecorded/preDemo.php on line 43

# Controller
public function insertData(){
        // print_r($_POST);exit;

        if($this->request->post['name'] && $this->request->post['email'] && $this->request->post['contactNumber'] && $this->request->post['businessType'] && $this->request->post['businessName'] && $this->request->post['role'] ) {

$data = array(
$name = $this->request->post['name'],
$email = $this->request->post['email'],
$contactNumber = $this->request->post['contactNumber'],
$businessType = $this->request->post['businessType'],
$businessName = $this->request->post['businessName'],
$role = $this->request->post['role']);
} 

else {
$name = 0;
}
// echo "<pre>";print_r($data);
$this->load->model('prerecorded/preDemo');
$this->preDemo->preDemo1($data);



    }
# Model ##########
<?php
class ModelPrerecordedPreDemo extends Model {
    public function preDemo1($data) {

        $this->db->insert("",$data);
    }
}

2 Answers2

1

correct load function from model:

$this->prerecorded_preDemo->preDemo1($data);
ALarik
  • 11
  • 2
0

There seems to be a naming problem with your model. File name an the class inside the file much match. You're also not following the file naming conventions of CodeIgniter.

The model file preDemo.php should probably be named Pre_demo.php and be declared like this

class Pre_demo extends Model {

With that done the model should load successfully (which it clearly does not in your code).

$this->load->model('prerecorded/pre_demo');
$this->pre_demo->preDemo1($data);
DFriend
  • 8,869
  • 1
  • 13
  • 26