[eluser]James_B[/eluser]
Hi guys im trying to create a blog page in a web-based application using php and CI and when I currently load the page I'm getting this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Blog::$Blog
Filename: controllers/blog.php
Line Number: 17
Fatal error: Call to a member function get_last_ten_entries() on a non-object in C:\xampp\htdocs\ci\web-project-jb\controllers\blog.php on line 17
I was thinking this was due to me not loading the model into the controller, but I had
Here's my code so far:
Blog controller
<?php
class Blog extends CI_Controller {
public function _construct()
{
parent::_construct();
$this->load->model('Blogmodel','Blog');
}
public function index()
{
$username = $this->session->userdata('username');
$viewData['username'] = $username;
$viewData['blogs'] = $this->Blog->get_last_ten_entries();
$this->load->view('shared/header');
$this->load->view('blog/blogtitle', $viewData);
$this->load->view('shared/nav');
$this->load->view('blog/blogiview', $viewData);
$this->load->view('shared/footer');
}
public function post()
{
if($this->input->post('act') =='create_post')
{
$this->Blog->insert_entry();
$this->load->view('blog/posted');
}
else
{
$this->load->helper('form');// Load the form helper.
// Lets set the stuff that will be getting pushed forward...
$data = array();
$data['form_open']=form_open();
$data['form_title'] = form_input(array('name' => 'title'));
$data['form_text'] = form_textarea(array('name' => 'text'));
$data['form_hidden'] = form_hidden('act','create_post');
$data['form_submit'] = form_submit('submit','Make Post');
$this->load->view('blog/post', $data);
}
}
}
blogmodel:
<?php
class Blogmodel extends CI_Model
{
public function _construct()
{
parent::__construct();
}
public function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
public function insert_entry()
{
$this->title = $this->input->post('title');
$this->body = $this->input->post('text');
$this->date = time();
$this->db->insert('entries',$this);
}
}
and my blogview:
<?
foreach($blogs AS $viewData)
{
$id = $viewData->id;
$title = $viewData->title;
$body = $viewData->body;
?>
<h1><?=$title?></h1>
<?=$body?>
<hr>
<?
}
?>
Thanks guys, im just so frustrated at the moment...