Welcome Guest, Not a member yet? Register   Sign In
blog lesson
#1

[eluser]anjelo[/eluser]
Hi can help me?

following the lesson blog in the tutorial I've founded an error:

"A PHP Error was encountered

Severity: Notice

Message: Undefined variable: db

Filename: controllers/blog.php

Line Number: 14

Fatal error: Cannot access empty property in C:\Programmi\EasyPHP 2.0b1\www\CodeIgniter\system\application\controllers\blog.php on line 14"

HELP
#2

[eluser]mistress_shiira[/eluser]
have you loaded the database like this:
$this->load->database();
if you have and you still have that error,kindly check your config file...
#3

[eluser]anjelo[/eluser]
Thank's, I resolved, the trouble is in the tutorial blog, the database is loaded in the librry array not in the core, in autoload.php.

Thank's
#4

[eluser]ELRafael[/eluser]
that video tutorial is too old. But if you read the autoload file you'll see an explaination!
#5

[eluser]WavyDavy[/eluser]
[quote author="ELRafael" date="1195071490"]that video tutorial is too old. But if you read the autoload file you'll see an explaination![/quote]

Thanks ELRafael,

Your response helped me solve the same problem, I simply removed the
$autoload['core'] = array('database');
that I had and replaced it with the following code that was in the autoload commnts

$autoload['libraries'] = array('database', 'session', 'xmlrpc');


Edit: I only managed to get a little further until I reached the point where I was using the anchor property from the url helper, then I started getting an error that said this;


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: anchor

Filename: views/blog_view.php

Line Number: 13
#6

[eluser]WavyDavy[/eluser]
Bump!

Can anyone help?
#7

[eluser]Sarre[/eluser]
Did you load the url helper?
$this->load->helper("url");
#8

[eluser]Seppo[/eluser]
It says undefined variable anchor... and anchor is a function... Are you using $anchor? you have to use
Code:
anchor('path/to/url', 'title');
#9

[eluser]WavyDavy[/eluser]
This is the code I have:

blog.php

Code:
<?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        
    }

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

}


?>

and this is the code for blog-view.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body &gt;
  <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>
    
    <p>&lt;?=$anchor("blog/comments/".$row->id, "Comments");?&gt;</p>
    
    <hr />

  &lt;?php endforeach; ?&gt;
  &lt;/body&gt;
&lt;/html&gt;

The code is exactly the same as the tutorial, but in the tutorial he does this wierd thing where he doesnt put the comments table in until well after he has written this code, he even deliberately tests this code so he gets error 404 pages so he can show the path url in the browser.

Its like he is doing things back to front, shouldnt he have created the comments table before writing this code? I am going to try creating a comments table and see what this does.
#10

[eluser]Sarre[/eluser]
As Seppo said: remove the "$" in front of the anchor-call:
Code:
<p>&lt;?=$anchor("blog/comments/".$row->id, "Comments");?&gt;</p>
Should be:
Code:
<p>&lt;?=anchor("blog/comments/".$row->id, "Comments");?&gt;</p>




Theme © iAndrew 2016 - Forum software by © MyBB