Welcome Guest, Not a member yet? Register   Sign In
Trailing slash in tutorial
#8

[eluser]pointmanx[/eluser]
[quote author="DarkManX" date="1343475499"]index.php/news/ would match this one:
Code:
$route[‘news/(:any)’] = ‘news/view/$1’;

index.php/news this one:
Code:
$route[‘news’] = ‘news’;

try to put out the uri you have been led to.[/quote]

@DarkManX: you probably mean output...i.e. something like an echo?

Here's what I did (temporarily) to check the portion of the uri that was getting sent as the slug:

(inside /appplication/controllers/news.php)
Code:
public function view($slug)
{
  echo $slug;

  $data['news_item'] = $this->news_model->get_news($slug);
  ...
}

It turned out that when following the tutorial routing:
Code:
$route[‘news/create’] = ‘news/create’;
$route[‘news/(:any)’] = ‘news/view/$1’;
$route[‘news’] = ‘news’;
I was getting back the segment pointing to the view function, not the segment pointing to the slug. My solution was to add the 'view' segment into the routing rule:

Code:
$route[‘news/create’] = ‘news/create’;
$route[‘news/view/(:any)’] = ‘news/view/$1’;
$route[‘news’] = ‘news’;

This means that the only way to get to the item identified by the slug segment is to do so directly off of the view function segment. Perhaps this was not what the author intended, but there's no hint in the tutorial to say where
Code:
$1
comes from, so there's no other reasonable assumption than it corresponds with the segments that fall under
Code:
(:any)
which, based on my echo result, gets truncated to only the first segment (removes everything after and including the '/')

Hope this helps to shed some light on the issue.



PS--
@InsiteFX (or whoever is the author of the tutorial):
Please review this and update your tutorial as necessary, for the sake of other new users who, in trying just to get the basics, run across this issue and potentially get frustrated before they have enough understanding of routing to troubleshoot what is going on.


Messages In This Thread
Trailing slash in tutorial - by El Forum - 07-26-2012, 12:26 AM
Trailing slash in tutorial - by El Forum - 07-27-2012, 02:38 AM
Trailing slash in tutorial - by El Forum - 07-27-2012, 10:39 AM
Trailing slash in tutorial - by El Forum - 07-28-2012, 01:00 AM
Trailing slash in tutorial - by El Forum - 07-28-2012, 04:38 AM
Trailing slash in tutorial - by El Forum - 07-28-2012, 06:28 AM
Trailing slash in tutorial - by El Forum - 07-28-2012, 01:47 PM
Trailing slash in tutorial - by El Forum - 08-24-2012, 05:32 PM
Trailing slash in tutorial - by El Forum - 08-25-2012, 05:36 PM
Trailing slash in tutorial - by El Forum - 03-09-2013, 09:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB