CodeIgniter Forums
[Solved] CI 2: Help with model not being loaded - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Solved] CI 2: Help with model not being loaded (/showthread.php?tid=36737)



[Solved] CI 2: Help with model not being loaded - El Forum - 12-13-2010

[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


[Solved] CI 2: Help with model not being loaded - El Forum - 12-13-2010

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


[Solved] CI 2: Help with model not being loaded - El Forum - 12-13-2010

[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.