samedi 18 avril 2015

CodeIgniter -Error Call to a member function model() on a non-object

I'm creating a registering from. Whenever I try to insert data to db it throws this error.



A PHP Error was encountered Severity: Notice Message: Undefined property: insert_ctrl::$insert_model Filename: controllers/insert_ctrl.php Line Number: 38 Fatal error: Call to a member function form_insert() on a non-object in C:\xampp\htdocs\NewProject\application\controllers\insert_ctrl.php on line 38



This is my insert_ctrl.php



<?php

class insert_ctrl extends CI_Controller{

function _construct()
{
parent :: _construct();
$this->insert_model->form_insert($data);

}

function index()
{
//Including validation library
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class ="error">','</div>');

//Validating name field
$this->form_validation->set_rules('dname','Username','required|min_length[5]|max_length[15]');
$this->form_validation->set_rules('demail','Email','required|valid_email');
$this->form_validation->set_rules('dmobile','Mobile No.');
$this->form_validation->set_rules('daddress','Adress','required|min_length[10]|max_length[50]');

if($this->form_validation->run()==FALSE)
{
$this->load->view('insert_view');
}
else {
//Setting values for db table
$data=array(
'Student_Name'=>$this->input->post('dname'),
'Student_Email'=>$this->input->post('demail'),
'Student_Mobile'=>$this->input->post('dmoblie'),
'Student_Address'=>$this->input->post('daddress')

);
//Transfering data to model
$this->insert_model->form_insert($data);
//loading view
$this->load->view('insert_view');
}
}
}

//insert_model.php

<?php
class insert_model extends CI_Model{
function _construct()
{
parent :: _construct();


}

function form_insert($data)
{
$this->db->insert('student',$data);
}
}
?>

Aucun commentaire:

Enregistrer un commentaire