CodeIgniter Forums
Undefined property: Blog::$db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Undefined property: Blog::$db (/showthread.php?tid=13505)



Undefined property: Blog::$db - El Forum - 11-25-2008

[eluser]featureBlend[/eluser]
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:

Code:
<?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
    
    }

    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

Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<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>

<hr>

&lt;?php endforeach; ?&gt;



&lt;/body&gt;
&lt;/html&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.


Undefined property: Blog::$db - El Forum - 11-25-2008

[eluser]pistolPete[/eluser]
You need to load the database class.
Have a look at the documentation: http://ellislab.com/codeigniter/user-guide/database/connecting.html

Either you load it manually using
Code:
$this->load->database();
in every controller which needs a database connection, or you use the autoloading feature.


Undefined property: Blog::$db - El Forum - 11-25-2008

[eluser]featureBlend[/eluser]
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.


Undefined property: Blog::$db - El Forum - 04-17-2010

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