Welcome Guest, Not a member yet? Register   Sign In
Hyphens in URL to underscores in class/method names
#1

(This post was last modified: 12-16-2014, 12:36 PM by sneakyimp.)

OK so I have seen a variety of suggestions about how to translate hyphens in one's url to underscores in the class and method names, but there seem to be few problems:
1) using routes requires tedious maintenance of the routes.php file. This is a non-starter for complex projects and also presents problems with a large dev team. We can't have everyone changing this file all the time.
2) The quick fix described here:
http://ianluckraft.co.uk/2011/01/codeign...en-in-url/
alters CodeIgniter core source code which is a no-no and could present problems if we are trying to upgrade our CI install.
3) Extend CI_Router class
https://ellislab.com/forums/viewthread/114640/#922998
Can someone explain to me what happens when you put his file in application/core?
Problem with this approach is that it maps first two segments of your url whether or not these are intended to be interpreted as class/method or not.

Is there any recommended/orthodox/canonical way to accomplish this in CI 2?
EDIT: Ideally this approach would affect only class and method names that are actually existing/valid such that any fractions of the url that were not intended as class/method names would not be affected.
EDIT: Added link I originally forgot about a quick fix.
Reply
#2

CI 3.0-dev has this feature as a configurable option.
Reply
#3

(12-16-2014, 12:25 PM)Narf Wrote: CI 3.0-dev has this feature as a configurable option.
I was aware CI 3 has this feature, but CI 3 has still not been released yet. Also, it worries me a bit that they have defined this setting in the routes file:
Code:
$route['translate_uri_dashes'] = FALSE;
Seems a bit ad-hoc to me for a brand new framework version.

I may be able to convince my collaborators to switch but I am not optimistic.

That said, is there an recommended/orthodox/canonical way to do this? Perhaps for starters someone could explain to me what we are doing when we extend CI_Router. Seems odd to me that CI would automatically make use of this class without some kind of configuration being changed.
Reply
#4

(12-16-2014, 12:45 PM)sneakyimp Wrote:
(12-16-2014, 12:25 PM)Narf Wrote: CI 3.0-dev has this feature as a configurable option.
I was aware CI 3 has this feature, but CI 3 has still not been released yet. Also, it worries me a bit that they have defined this setting in the routes file:

Code:
$route['translate_uri_dashes'] = FALSE;
Seems a bit ad-hoc to me for a brand new framework version.

I may be able to convince my collaborators to switch but I am not optimistic.

That said, is there an recommended/orthodox/canonical way to do this? Perhaps for starters someone could explain to me what we are doing when we extend CI_Router. Seems odd to me that CI would automatically make use of this class without some kind of configuration being changed.

Well... it is route related. So I don't actually think that is "ad-hoc".
Reply
#5

(12-17-2014, 03:00 AM)Avenirer Wrote: Well... it is route related. So I don't actually think that is "ad-hoc".
On further reflection, I guess you're right. I was just thinking that the file is called 'routes' and that all the other values in $routes seem to have a controller path as a value. This particular value in that same array is a boolean.

Still wondering about this:
sneakyimp Wrote:Perhaps for starters someone could explain to me what we are doing when we extend CI_Router. Seems odd to me that CI would automatically make use of this class without some kind of configuration being changed.
Anyone Bueller? Ferris Bueller?
Reply
#6

I have upgraded to CI3 so this issue is resolved for me.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB