[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