• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building a Blog with Codeigniter tutorial question [Solved!]

[eluser]Mantra of Doom[/eluser]
Hello everyone,
I've been following a tutorial called Building a Blog with Codeigniter on eeinsider.com, which is a pretty good tutorial for me with the exception that it promises a fourth part that was never posted.

I noticed that in the link to the post with the full post, it uses the following code to make the link:
a href="/blog/entry/&lt;?php echo $entry->url_title; ?&gt;">&lt;?php echo $entry->title; ?&gt;</a>

It seems that this method only really works if there is an .htaccess file to take out the "index.php" from the url. This seems to work okay, but I wonder if there isn't a better way.

I'm just wondering if this might be the reason I'm having issues adding pagination to a blog built with this tutorial. Any hints or a poke in the right direction would be helpful. I love codeigniter so far and the user guide and community are full of helpful things. Thanks in advance for any advice.

I'm posting the code for those that have not seen this tutorial yet.

The Model
//Gets all entries in the blog table
    public function get_all_entries()
        $this->db->select('summary, title, url_title, author');
        $query = $this->db->get('blog');
        if ($query->num_rows() > 0)
          return $query->result();
        } else {
          return array();

    //gets a single entry based on its url title
    public function get_entry($url_title)
      $this->db->select('title, entry, author')->where('url_title', $url_title);
      $query = $this->db->get('blog', 1);
      if ($query->num_rows() == 1)
        return $query->row();
      } else {
        return false;
The View
  &lt;?php foreach ($query as $entry) { ?&gt;
  <div class="blog_entry">
    <h2>< a href="/blog/entry/&lt;?php echo $entry->url_title; ?&gt;">&lt;?php echo $entry->title; ?&gt;</a></h2>
    <span class="metadata">&lt;?php echo $entry->author; ?&gt;</span>
    <p>&lt;?php echo $entry->summary; ?&gt;</p>
  &lt;?php } ?&gt;

Check out the anchor function of the URL Helper.

Also, for more up-to-date tutorials, check out the nettuts CodeIgniter from Scratch video series.

[eluser]Cesar Kohl[/eluser]
I would do something like this:

First, enable URL Helper:


Second, use anchor function to create a link:


[eluser]Mantra of Doom[/eluser]
Thanks bretticus and Cesar Kohl, the URL helper is what I was looking for.

The only thing with this method

is that I get this error:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: entry_title

Filename: news/news_main.php

Line Number: 12

Line 12 is where my anchor tag is. Where is it that I define $entry_title since $entry comes from the query loop in the view?


instead of:

[eluser]Mantra of Doom[/eluser]
I feel really stupid now, thanks LuckyFella73!

I thought I had tried that and it didn't work. I guess I must have missed something simple.

Thanks for all the help guys, I'm going to mark this as solved.

Naaah don't feel stupid - making such kind of mistakes will
never end. They just become rare more and more Wink

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.