Welcome Guest, Not a member yet? Register   Sign In
Tutorial error...?? (RESOLVED)
#21

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

[eluser]Unknown[/eluser]
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'].

Code:
<?php
class News extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('news_model');
}

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".
#23

[eluser]Aken[/eluser]
If you continue reading the tutorial page, the view() method is revamped with additional logic and the correct updated code.
#24

[eluser]Unknown[/eluser]
[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.
Code:
// In News __construct():
$this->load->helper('url');

// 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
Code:
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!




Theme © iAndrew 2016 - Forum software by © MyBB