Welcome Guest, Not a member yet? Register   Sign In
Userguide CI 3.0 error
#1

Hi,

 In this page: http://www.codeigniter.com/userguide3/tu...ction.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
Reply
#2

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

(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 ?>
Reply
#4

make sure you added the route for it, look at the very bottom of that page.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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.
Reply
#6

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';
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB