• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routing bug (is it a bug?)

[eluser]Derek Allard[/eluser]
I'm happy to expand on the userguide. Who wants to write it up and post it here so that we can all vet it?

Something simple along the lines of adding the how-to to the non-regex examples would suffice i feel, because the functionality is there its just not documented in all the right places and can be confusing if you lazy read like i do Smile


<p>Here are a few routing examples:</p>

<code>$route['journals'] = "blogs";</code>
<p>A URL containing the word "journals" in the first segment will be remapped to the "blogs" class.</p>

<code>$route['blog/joe'] = "blogs/users/34";</code>
<p>A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method.  The ID will be set to "34".</p>

<code>$route['product/:any'] = "catalog/product_lookup";</code>
<p>A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the  "product_lookup" method.</p>

<code>$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";</code>
<p>A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to the function.</p>

<p class="important"><strong>Important:</strong> Do not use leading/trailing slashes.</p>

I use this method for SEO optimization of links by: -

class Events extends Controller {

    function by_city_id($city_id, $city_name = '') {

and then in routes.php: -

$route['city/(:num)/(:any)'] = "events/by_city_id/$1/$2";

and then creating a link to /city/1459/boston-massachusetts would execute Events::by_city_id(1459, 'boston-massachusetts'). You ignore the second value as it purely for SEO as you already have the correct city by its id from the first variable.

But whether thats worth including as example usage also is up for debate.

[eluser]Derek Allard[/eluser]
Thanks ptrippett. Anyone else have anything to add here?

[eluser]Référencement Google[/eluser]
Nothing more to add from me, that helps really to clarify this user guide part.

hey, great work, ptrippett. I especially like your SEO link example, I think it should be included.

I suggest changing the URI Routing page to move the Examples section below the Regex section, so the concepts are explained before they're demonstrated. It would also be helpful to have a "related topics" or "further information" section at the bottom of the page with off-site links to things like PHP.net's definitions of back-references and regular expressions.

<h2>Related Topics</h2>
   <a href="http://us2.php.net/manual/en/regexp.reference.php">PHP Regular Expressions</a><br />
   <a href="http://us2.php.net/manual/en/regexp.reference.php#regexp.reference.back-references">Back References</a><br />

Regarding ptrippett's SEO example: if you are just throwing away that second parameter, the route could be simplified to:

$route['city/(:num)/:any'] = "events/by_city_id/$1";

And finally, to play editor a bit: in the final example ptrippett provided, 'product/(:num)', the words "and anything in the second" should be changed to "and any number in the second"

[eluser]Derek Allard[/eluser]
OK, I've added ptrippett's example to the userguide. Thanks all!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.