Welcome Guest, Not a member yet? Register   Sign In
'mydomain.com/directory' url possible?
#1

[eluser]hht1230[/eluser]
Can I create a Directory class so I can include /directory in a url? When I try, I get a "Cannot redeclare class Directory" error message, I assume because of directory_helper.php. Is there a way to work around this? Thanks for any suggestions.
#2

[eluser]Mirage[/eluser]
There will be situations when your url will collide with a classname or function name. This is one of the reasons I'd prefer CI would support use of suffixes out of the box, e.g:

- User_Model
- Directory_Controller
- Index_View

Interestingly enough that's how it was done for helpers and plugins. There are other reasons I like this verbose notation but since it's not available without rewriting a bunch of core code let's just forget about that.

What you CAN do in case of collisions is to create e.g. a custom controller name and write a route to map to it:

Code:
// in routes.php config
$routes['directory(.*)']='Directory_Controller$1';

// controller Directory_Controller.php
class Directory_Controller extends Controler {

// yada yada

}

HTH,
-m
#3

[eluser]hht1230[/eluser]
Thanks, m. That worked very well (with a couple typo fixes):

Code:
// in routes.php config
$route['directory(.*)']='Directory_Controller$1';

// controller Directory_Controller.php
class Directory_Controller extends Controller {

}
#4

[eluser]Mirage[/eluser]
:-) Those weren't typos.. I'm running a custom PHP dialect on my development machine... glad you were able to translate.

-m




Theme © iAndrew 2016 - Forum software by © MyBB