Welcome Guest, Not a member yet? Register   Sign In
News article pages 404
#1

[eluser]CodeIgNewbie[/eluser]
I've followed the initial tutorial, and everything's fine, except that the article pages aren't being found. The articles are being created and displayed in the http://www.trainstormbeta.co.uk/ci/index.php/news/ page, but not singularly when clicked through - e.g. http://www.trainstormbeta.co.uk/ci/index...nd-article

I'm really feeling my way, and absorbing it slowly, but I'm stumped at the moment with this. Here's the routing file:

[code ]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
[/code ]

Shouldn't there be another view page for this? If not, how is it possible to style the results?
#2

[eluser]Aken[/eluser]
Look at your individual article's URL. There's two "news" segments. You should figure out why.
#3

[eluser]CodeIgNewbie[/eluser]
You're right, there are two 'segments', but you're also wrong - I can't figure it out. No matter what I try in routes.php I can't lose one. This is my first day at this and I've nothing to look back at yet - no solid ground. Is it a routing issue? In routes.php?
#4

[eluser]kevin.smith84[/eluser]
I don't believe telling someone they are wrong will warrant you getting anymore help from them.
#5

[eluser]CodeIgNewbie[/eluser]
I'm just pointing out that I'm not as clever as you. It was meant to be lighthearted, sorry.
#6

[eluser]Aken[/eluser]
Hint: find where the link you're clicking is being generated. Hint two: relative URL. Hint three: search this forum.
#7

[eluser]CodeIgNewbie[/eluser]
I'm sorry, I just don't get it. Is there something I missed in the tutorial? If not, why leave people to flounder?

I've done a lot of reading on relative URLs and found that I might need to load a URL Helper with the following code: $this->load->helper('url'); Problem is, at the moment, I'm so unfamiliar with the framework because I can't move forward with it, that I've no idea where to put this code - and wherever I do put it, it does nothing.

I've also looked at several sites, such as: http://maestric.com/doc/php/codeigniter_relative_urls, but these are just beyond me at the moment.

I've managed to get rid of the double segment (can't remember how now though!), and the links look right, e.g. http://www.trainstormbeta.co.uk/ci/index...nd-article, but I'm still getting 404s. I'm pretty sure this is a routing issue, but I'm really scrabbling in the dark. Here's my route.php file as it stands:

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['404_override'] = '';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

I understand that you don't want to do the work for me (doing so serves no purpose, as it hinders learning), but on the other hand I can't learn if I have no tangible guide, and the tutorial is either ambiguous or incomplete. I really do appreciate the time and effort you are offering.
#8

[eluser]CodeIgNewbie[/eluser]
Just created another news article and I'm back to double segments. What on Earth is going on?
#9

[eluser]CodeIgNewbie[/eluser]
OK, I've got rid of the double segment again. I hope I've got this right, but I've removed the "news/" element from the "news/index.php" file.

The link still doesn't resolve though.

Sorry, can't show the code as it renders incorrectly for some reason.
#10

[eluser]Aken[/eluser]
Double segments show up in your browser's location bar because you clicked a link that sent you to that location. If you fix how the link is being generated, you'll fix the double segment showing up.

Your routes could be an issue if you didn't put them in the right place. I can't see your whole application, but they should be in application/config/routes.php (there's already a file there waiting for you).

The code in your controller's view() method can also throw a 404 error using show_404() if it can't find a news item. Make sure that that isn't what's creating the 404 error, also.




Theme © iAndrew 2016 - Forum software by © MyBB