Welcome Guest, Not a member yet? Register   Sign In
[Solved] CI 2: Help with model not being loaded
#1

[eluser]cmh24[/eluser]
Hi everybody,
get following error message while trying to build a basic blog.
Fatal error: Call to a member function insert_post() on a non-object in C:\xampp\htdocs\CI-2\application\controllers\blog.php on line 24

I'm a new to CI and not pretty experienced with PHP, but I am trying my best. I use CI2 from bitbucket and autoloaded the database.

So here is the Code.
Code:
<?php

class Blog extends CI_Controller {

    function __constuct()
    {
        parent::__construct();
        $this->load->model('blog_model');
    }
    
    function index()
    {
        $data['results'] = $this->blog_model->get_all();
        $this->load->view('blog_view',$data);
    }
    
    function add_entry()
    {
        $data = array (
        'title'         => $this->input->post('title'),
        'author'    => $this->input->post('author'),
        'body'         => $this->input->post('body')
    );
    $this->blog_model->insert_post($data);
    }
    
}
And here is the model
Code:
<?php

class Blog_model extends CI_Model {

    function get_all()
    {
    $query = $this->db->get('posts');
    return $query->result();
    }
    
    function count_all()
    {
    $query = $this->db->get('posts');
    return $query->num_rows();
    }

    function insert_post($data)
    {
    $this->db->insert('posts',$data);

    redirect('/blog');
    }
}

I am running everything on my local machine, the XAMP version is up to date.

Greetings from Germany
Max
#2

[eluser]tomcode[/eluser]
You have an type error in Your Controller constructor __constuct instead of __construct
#3

[eluser]William Lopes[/eluser]
Again see this happen, I'm think this CodeIgniter 2.0 still don't is finished for work.

I'm working CodeIgniter 1.7.3.

Hugs.




Theme © iAndrew 2016 - Forum software by © MyBB