• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial error...?? (RESOLVED)

[eluser]CMG Dev[/eluser]
Same problem here. Tutorial should be fixed. Other way is confusing.

Thanks Peter for being the first to come up with the right answer. What I found though is that you really only have to change one line. Inside the controller in the view function change $data['news'] to $data['news_item'].

class News extends CI_Controller {

public function __construct()

public function index()
  $data['news'] = $this->news_model->get_news();

public function view($slug)
  $data['news_item'] = $this->news_model->get_news($slug);

This makes sense semantically because the view function in the controller is meant to retrieve only one "news_item." The "news/view" view then still only displays one "news_item" and the "news/index" view displays a collection of "news_items".

If you continue reading the tutorial page, the view() method is revamped with additional logic and the correct updated code.

[quote author="Aken" date="1327372880"]What's the URL of the page giving you the 404 error? You can use example.com instead of your live domain.

A couple things you can try:

1) Load the URL helper to your controller constructor, and use the site_url() function to help generate the news slug URL.
// In News __construct():

// Replace your link URL with:
<?php echo site_url('news/' . $news_item['slug']); ?>

2) In your controller's view() method, replace show_404() with something like
exit('The error is here.');
If your browser then displays the error message instead of CI's 404 page, then you know your model isn't returning the data it's expected to.[/quote]

This worked perfect, thank you very much!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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