BLOG
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: blogs
Filename: views/blog.php
Line Number: 8
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\views\blog.php
Line: 8
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\controllers\Blog.php
Line: 17
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\index.php
Line: 315
Function: require_once
Fatal error: Call to a member function result() on null in
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\views\blog.php on line
8
A PHP Error was encountered
Severity: Error
Message: Call to a member function result() on null
Filename: views/blog.php
Line Number: 8
Backtrace:
views/blog.php
PHP Code:
<html>
<h1>BLOG</h1>
<?php foreach ($blogs->result() as $row) : ?>
<li>
<?php echo $row->date; ?><br>
<?php echo $row->title; ?><br>
<?php echo $row->content; ?><br>
</li>
<?php endforeach; ?>
</html>
controllers/blog.php
PHP Code:
<?php
class Blog extends CI_Controller {
public function index()
{
$this->load->model('blog_model');
//$data['query'] = $this->blog->insert();
$data['title'] = $this->blog_model->select_blog();
$data['content'] = $this->blog_model->select_blog();
$data['date'] = $this->blog_model->select_blog();
$this->load->view('blog', $data);
//$this->load->view('blog');
}
}
?>
models/blog_model.php
PHP Code:
<?php
class Blog_model extends CI_Model {
public $title;
public $content;
public $date;
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
$this->load->database();
}
public function select_blog()
{
$query = $this->db->query('SELECT * FROM blog');
return $query->result();
// return 'masuk loh';
}
public function insert_blog()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('blog', $this);
}
public function update_blog()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('blog', $this, array('id' => $_POST['id']));
}
}
?>
How to fix the above error?
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\views\blog.php
Line: 8
Line: 8 <?php foreach ($blogs->result() as $row) : ?>
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\controllers\Blog.php
Line: 17
Line: 17 $this->load->view('blog', $data);
" If I looks more intelligence please increase my reputation."