CodeIgniter Forums
Userguide CI 3.0 error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Userguide CI 3.0 error (/showthread.php?tid=1217)



Userguide CI 3.0 error - reszko - 02-19-2015

Hi,

 In this page: http://www.codeigniter.com/userguide3/tutorial/news_section.html there is an error in the view index.php code that shows the news.

 The link is pointing to "/news" instead of "/view".

 The way is showed, when all the news are listed, when user clicks the link "View Article", he is taken to a wrong URI: /news/news/article-slug

 The correct way would be like this: /news/view/article-slug

Thank you

Fabio


RE: Userguide CI 3.0 error - Narf - 02-19-2015

Sorry, but I can't find the piece that you're referring to. Can you quote it here?


RE: Userguide CI 3.0 error - reszko - 02-19-2015

(02-19-2015, 01:48 PM)Narf Wrote: Sorry, but I can't find the piece that you're referring to. Can you quote it here?

Hi, below the code. Look the piece of code of href that creates the View Article link. That "news" word must be replaced to "view".

The code above gets all news records from the model and assigns it to a variable. The value for the title is also assigned to the $data[‘title’] element and all data is passed to the views. You now need to create a view to render the news items. Create application/views/news/index.php and add the next piece of code.

Code:
<h2><?php echo $title ?></h2>

<?php foreach ($news as $news_item): ?>

       <h3><?php echo $news_item['title'] ?></h3>
       <div class="main">
               <?php echo $news_item['text'] ?>
       </div>
       <p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>

<?php endforeach ?>



RE: Userguide CI 3.0 error - InsiteFX - 02-20-2015

make sure you added the route for it, look at the very bottom of that page.


RE: Userguide CI 3.0 error - reszko - 02-20-2015

Yes, I added the route, but the tutorial only worked when I changed the link to 'view'. If you do like the tutorial says, when the user clicks in the link to view the article, the URI shows like this: /news/news/slug-of-article and the article is not found.

If I am doing something wrong, please warn me.

Thank you.

Sorry for the english, I am not american.


RE: Userguide CI 3.0 error - Narf - 02-20-2015

Well, InsiteFX was warning you that you're doing something wrong ...

If the link doesn't work, you're just missing this route:

Code:
$route['news/(:any)'] = 'news/view/$1';



RE: Userguide CI 3.0 error - reszko - 02-20-2015

Ok, but look the original code and compares it with the route:

Code:
<p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>

Route:

Code:
$route['news/(:any)'] = 'news/view/$1';

That way, it wold be like this: /news/news/article-slug, and does not work.

But if I change to 'view' in href, it works, beacause the URI works like this: /news/view/article-slug

Fabio


RE: Userguide CI 3.0 error - Narf - 02-20-2015

The route tells that if you get a request of 'news/foo', it will be treated as if it was 'news/view/foo'.

It's a simple from->to conversion, on which the link creation relies.


RE: Userguide CI 3.0 error - reszko - 02-20-2015

Ok, maybe I am doing something wrong. I followed exactally the tutorial and it didn't work, only when I changed to 'view' it worked.

Thank you.


RE: Userguide CI 3.0 error - Narf - 02-20-2015

(02-20-2015, 08:57 AM)reszko Wrote: Ok, maybe I am doing something wrong. I followed exactally the tutorial and it didn't work, only when I changed to 'view' it worked.

Thank you.

What does your config/routes.php contain after the tutorial? If you paste its contents here, we'll be able to tell you what you did wrong with it.