Welcome Guest, Not a member yet? Register   Sign In
Routing bug (is it a bug?)
#11

[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?
#12

[eluser]ptrippett[/eluser]
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

Code:
<h2>Examples</h2>

<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: -

Code:
class Events extends Controller {

    function by_city_id($city_id, $city_name = '') {
        //Blah
    }
    
}


and then in routes.php: -

Code:
$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.
#13

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

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

[eluser]drfloob[/eluser]
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.

Code:
<h2>Related Topics</h2>
<p>
   <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 />
   [...]
</p>

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

Code:
$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"
#16

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




Theme © iAndrew 2016 - Forum software by © MyBB