02-12-2012, 02:44 PM
[eluser]jamiejonks[/eluser]
I have just encountered a similar problem. Shame these comments can’t be shown underneath the tutorial rather than hidden away in a forum. Anyway, this is what I found:
1) The view (views/news/index.php) should contain a simpler href – just the PHP bit without ’news/‘ at the beginning.
2) if when creating the database records you used spaces in your slug field, you’ll get the 404 error from your new controller. I thought the purpose of the slug field was for a subheading to the news article, so of course my examples did contain spaces. The solution was to first encode the slug in the view (views/news/index.php):(Actually, that step isn’t strictly necessary because the browser will do it automatically, but it makes the final HTML follow the spec)
NB I’ve left the opening angle bracket off the a tag here, because the forum wouldn’t let me include links in my post.
Then, in the news controller, add the line or similar to the view() function (method). It will now work.
I don’t know if this is the best way to do it.
I have just encountered a similar problem. Shame these comments can’t be shown underneath the tutorial rather than hidden away in a forum. Anyway, this is what I found:
1) The view (views/news/index.php) should contain a simpler href – just the PHP bit without ’news/‘ at the beginning.
2) if when creating the database records you used spaces in your slug field, you’ll get the 404 error from your new controller. I thought the purpose of the slug field was for a subheading to the news article, so of course my examples did contain spaces. The solution was to first encode the slug in the view (views/news/index.php):
Code:
<p>a href="<?php echo rawurlencode($news_item['slug']) ?>">View article</a></p>
NB I’ve left the opening angle bracket off the a tag here, because the forum wouldn’t let me include links in my post.
Then, in the news controller, add the line
Code:
$slug = rawurldecode($slug);
I don’t know if this is the best way to do it.