1

below is my books_controller.php

function books_s()
{
    $this->load->helper('form');
    $this->load->helper('html');
    $this->load->model('books_model');

    $sri=$this->input->post();
    print_R($sri);

    if($this->input->post())
    {
    $bookme=$this->load->books_model->post_books(); 

    }
    $this->load->view('header.php');    
}

i have not placed my books_view.php code bcos you can see in my controller code i have done print_R($sri); i can see the the values are posted from view page to controller page ...out put is

Array ( 
    [Id] => 4 
    [title] => just testng 
    [text] => goooo 
    [submit] => submit 
    ) 

` iam also getting error message

Message: Undefined property: CI_Loader::$books_model

Filename: controllers/books_Controller.php books_controller.php i know its an issue with my model code

function books_model()
{
    parent::__Construct();
}

function post_books()
{
    $this->load->database();
    $id=$this->input->post('id');
    $title=$this->input->post('title');
    $text=$this->input->post('text');

    $data=array('id'=>$id,'title'=>$title,'text'=>$text);
    $this->db->insert('data',$data);
}

Can you guys help me to find where am I doing the mistake ?

2 Answers 2

2

Your model should be like this

Class Books_Model Extends CI_Model{

    function __construct()
    {
        parent::__construct();
    }

    function post_books()
    {
        $this->load->database();
        $id=$this->input->post('id');
        $title=$this->input->post('title');
        $text=$this->input->post('text');

        $data=array('id'=>$id,'title'=>$title,'text'=>$text);
        $this->db->insert('data',$data);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1
$bookme=$this->load->books_model->post_books(); 

You have already loaded the model, so now you just need to access the instance so it should be:

$bookme=$this->books_model->post_books(); 

You also need to do this:

function __construct()
{
    parent::__construct();
}

However, it should not really be the thing causing the error as it should work either way, but the above is the correct way.

2 Comments

hmmm i got it cryptic....,,very silly mistake ..:(.... problem solved.. thanks dear...
@user1659450, you're welcome. It's always the small things that cause the headaches =o)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.