Welcome Guest, Not a member yet? Register   Sign In
Avoid controller name collisions
#1

[eluser]Unknown[/eluser]
Here's a sweet trick I use with my controllers. I know CodeIgniter doesn't use namespaces (and I understand that's not the most important point), but why don't use some of the advantages of PHP 5.3 ?

Simply change in CodeIgniter.php
Code:
$class  = $RTR->fetch_class();
by
Code:
$directory = str_replace('/','\\',$RTR->fetch_directory());
$class = 'controllers\\'.$directory.$RTR->fetch_class();

Now, you can add the namespace line on the top of your controller files, and use the same name twice (or more). This trick prevents collisions from your models folder too (using namespaces for your objects is the best way to solve that issue once and for all).

What do you think about ?


Messages In This Thread
Avoid controller name collisions - by El Forum - 02-02-2011, 06:02 PM
Avoid controller name collisions - by El Forum - 02-02-2011, 10:50 PM
Avoid controller name collisions - by El Forum - 02-02-2011, 11:01 PM
Avoid controller name collisions - by El Forum - 02-03-2011, 03:25 AM
Avoid controller name collisions - by El Forum - 02-03-2011, 07:23 AM
Avoid controller name collisions - by El Forum - 02-03-2011, 10:08 AM
Avoid controller name collisions - by El Forum - 02-03-2011, 09:08 PM
Avoid controller name collisions - by El Forum - 02-03-2011, 10:16 PM
Avoid controller name collisions - by El Forum - 02-21-2011, 02:44 PM
Avoid controller name collisions - by El Forum - 02-21-2011, 07:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB