Welcome Guest, Not a member yet? Register   Sign In
Undefined property: Blog::$db

I am receiving PHP error: Undefined property: Blog::$db - while connecting to my database.

Here is the code i used in the controller blog.php:


class Blog extends Controller {

    function Blog()

    function index()
        $data['title'] = "Ahad Bokhari loves Code Igniter";
        $data['heading'] = "My Blog Heading";
        $data['query'] = $this->db->get('entries');
        $this->load->view('blog_view', $data);


and here's the code for the the View file: blog_view.php

<title><?php echo $title; ?></title>
<h1>&lt;?php echo $heading; ?&gt;</h1>

&lt;?php foreach($query->result() as $row): ?&gt;
<h3>&lt;?php echo $row->title; ?&gt;</h3> //something wrong with my syntax?
<p>&lt;?php echo $row->body; ?&gt;</p>


&lt;?php endforeach; ?&gt;


I am not using shorthand codes for php since i am on a local server and dont know how to enable it...Yes i have setup all the files for the database

Any thoughts? I know im a newbie, but the minute i figure out how it works, the rest will become trivial.

You need to load the database class.
Have a look at the documentation: http://ellislab.com/codeigniter/user-gui...cting.html

Either you load it manually using
in every controller which needs a database connection, or you use the autoloading feature.

Thank you PistolPete, appreciated....

BTW if you all want to your server to accept PHP shorthand codes please change that in your php.ini file.

[eluser]sandeep nami[/eluser]
@pistol pete thanq very much

Theme © iAndrew 2016 - Forum software by © MyBB