I’m very new to CI so bare with me, but I have been reading all the docs and this forum but one thing, which might be trivial for some but of high value to us, is the ability to have fully qualified and optimized URLs.
This for example means that http://example.com/outsourcing-services/ is a better URL than just /services/, but php doesn’t allow the object names to contain ‘-’...and naming the controller file outsourcing-services.php while having the class be named ‘Outsourceservices’ doesn’t work either since then CI returns 404, file not found…
So how does one go about to have urls containing dashes? At highest level already. While still keeping the source neatly divided into the different controllers for different areas if wanted.
I’m sure it’s something easy I missed, but too much reading turns one blind sometimes.
Yash: Thanks for your fast response…I suppose one way would be to use mod_rewrite to splice a dash-one-dir-url to several sections…which kinda negates the point of not going from that to a normal file+parameter style right away…owell. :D
wiredesignz - 22 July 2008 12:41 PM
There is a little function in the CI url_helper named url_title() which may help here.
I’m very new to CI so bare with me, but I have been reading all the docs and this forum but one thing, which might be trivial for some but of high value to us, is the ability to have fully qualified and optimized URLs.
This for example means that http://example.com/outsourcing-services/ is a better URL than just /services/, but php doesn’t allow the object names to contain ‘-’...and naming the controller file outsourcing-services.php while having the class be named ‘Outsourceservices’ doesn’t work either since then CI returns 404, file not found…
So how does one go about to have urls containing dashes? At highest level already. While still keeping the source neatly divided into the different controllers for different areas if wanted.
I’m sure it’s something easy I missed, but too much reading turns one blind sometimes.
Google have said that they treat underscores in urls exactly the same as a dash in a url. They said this some time ago (i think it’s on Matt Cutts blog).
Meh.. Unfortunate you make that point, audiopleb. I don’t know why CI doesn’t just attempt to map dashed controller/function URI parameters to underscored class and class member function names. Well, actually, I do have a hunch why this isn’t done, but it still seems slightly ridiculous.
Three simple solutions remain. 1.) Abandon the dashes and adopt underscores, like audiopleb suggests. 2.) Override the necessary Router class member function(s) to make CI think of dashes as underscores. 3.) Lose the two-word URI param altogether. Just name the class “Outsourcing.” This last option is my favorite
So far, so good with overriding the Router library’s _set_request() method to change dashes found in the first two segments to underscores.
Attached is the MY_Router.php file (inside the .zip) that I’m using in my application/libraries/ directory and here is the addition to the method mentioned above: