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

[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.
#2

[eluser]pistolPete[/eluser]
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
Code:
$this->load->database();
in every controller which needs a database connection, or you use the autoloading feature.
#3

[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.
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB