Welcome Guest, Not a member yet? Register   Sign In
newbie question
#1

[eluser]Nuage[/eluser]
First of all hello to everybody,
I am a really really newbie.. I have been coding PHP for a few years. Also can be considered as a new OOP programmer.. Anyway, i have been reading and watching the tutorials of CI.
I am trying to do the blog thing.

this is my blog.php

Code:
<?php
class Blog extends Controller
{
    function Blog ()
    {
        parent::Controller();
    }

    function index()
    {
        $data['title'] = "My Blog Title";
        $data['heading'] = "My Blog Heading";
        $data['query'] = $this->db->get('entries');
        
        $this->load->view('blog_view', $data);
    }
}

?>


and this is my blog_view.php

Code:
<html>
<head>
<title><?= $title?></title>
</head>
<body>
    <h1>&lt;?= $heading?&gt;</h1>
&lt;?php foreach($query-result() as $row): ?&gt;
    
<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>

<hr>
&lt;?php endforeach; ?&gt;
    
&lt;/body&gt;
&lt;/html&gt;

but i get
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Blog::$db

Filename: controllers/blog.php

Line Number: 13

error. Why is that? I have done what it says on the tutorial video..
Thanks in advance.
#2

[eluser]Anthony Hull[/eluser]
http://ellislab.com/forums/viewthread/97989/
#3

[eluser]Nuage[/eluser]
Thank you very much Anthony. But i have already done the configurations on the autoload.php
so why did not CI load the database automatically?
#4

[eluser]Anthony Hull[/eluser]
[quote author="Nuage" date="1233360582"]Thank you very much Anthony. But i have already done the configurations on the autoload.php
so why did not CI load the database automatically?[/quote]

So you have this line in autoload.php?

$autoload['libraries'] = array('database');
#5

[eluser]Nuage[/eluser]
Oh no..
$autoload['core'] = array('database');
as shown in the tutorial video.. So it should be in the "libraries" section, instead of "core" section?
#6

[eluser]Anthony Hull[/eluser]
[quote author="Nuage" date="1233361285"]Oh no..
$autoload['core'] = array('database');
as shown in the tutorial video.. So it should be in the "libraries" section, instead of "core" section?[/quote]

Yes, according to the online userguide, the core section is deprecated and should not be used anymore.

I'm a newbie myself but that's what I read Smile
#7

[eluser]Nuage[/eluser]
Ahaamm.. I see Smile
Thank you very much for your help Anthony.
Also you are a newbie, you helped so much! Wink
#8

[eluser]Anthony Hull[/eluser]
No problem Smile




Theme © iAndrew 2016 - Forum software by © MyBB