ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem/Discrepancy in beginning tutorial discovered

December 03, 2012 7:39pm

Subscribe [1]
  • #1 / Dec 03, 2012 7:39pm

    eldorado2768

    2 posts

    In the first tutorial there is an error that occurs in the news controller and view. The tutorial shows the following code in the controller:

    public function view($slug)
    {
     $data['news_item'] = $this->news_model->get_news($slug);
    
     if (empty($data['news_item']))
     {
      show_404();
     }
    
     $data['title'] = $data['news_item']['title'];
    
     $this->load->view('templates/header', $data);
     $this->load->view('news/view', $data);
     $this->load->view('templates/footer');
    }

    The view file code is:

    echo '<h2>'.$news['title'].'</h2><p>';<br />
    echo $news['text'];

    That configuration produces an error. I was able to figure out that naming the $data array key as $data[‘news_item’] is what created the error. The table name in the database is “news”. When I changed the declaration to $data[‘news’] everything worked fine: Modified code in the controller:

    public function view($slug)
     {
      $data['news'] = $this->news_model->get_news($slug);
      
      if (empty($data['news']))
     {
      show_404();
     }
    
     $data['title'] = $data['news']['title'];
    
     $this->load->view('templates/header', $data);
     $this->load->view('news/view', $data);
     $this->load->view('templates/footer');
    
    }

    Updated code in view file:

    echo '<h2>'.$news['title'].'</h2><p>';<br />
    echo $news['text'];

    Anyone else going through this tutorial experienced the same issue?

     

  • #2 / Dec 03, 2012 8:41pm

    Aken

    2430 posts

    What user guide are you looking at? The one on EllisLab’s website is updated and correct, as should any user guide sent with 2.1.3 (and I think a couple previous versions as well).

  • #3 / Dec 03, 2012 10:24pm

    eldorado2768

    2 posts

    From the codeigniter home page, I clicked on “Skim this Manual” and was taken to this page:

    http://ellislab.com/codeigniter/user-guide/

    At the top of this page it says CodeIgniter User Guide Version 2.1.3

    The code I described can be found at this point in the tutorial:

    http://ellislab.com/codeigniter/user-guide/tutorial/news_section.html

     

  • #4 / Dec 04, 2012 12:38am

    Aken

    2430 posts

    As I said, the user guide is correct. Your view code differs from what the user guide has.

    And the database table name has nothing to do with your problem.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases