I'm new to CI. And just wanted to know where did I go wrong. Seems that I can't connect to my database. So I tried loading the database in the controller, just to see if it can connect and I can do queries. I did configure the database.php
and set everything up. But it displays as this.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Blog::$db
Filename: controllers/blog.php
contollers/blog.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
public function index() {
$this->load->model("blogmodel");
$articles = $this->blogmodel->get_articles_list();
echo $articles;
}
}
blogmodel.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blogmodel extends CI_Model {
function get_articles_list() {
$list = $this->db->query("SELECT * FROM foo");
return $list;
}
}
Hope you can help me. Thanks.