Welcome Guest, Not a member yet? Register   Sign In
Is there a standard way to get the application/controllers path?
#1

[eluser]Dave Stewart[/eluser]
I'm writing a utility Library that needs to scan the folder and print out a list of all the controller names and methods.

Cheers,
Dave
#2

[eluser]mironcho[/eluser]
Hi Dave,
You can use the APPPATH constant:
Code:
$controllers_path = APPPATH . 'controllers';
#3

[eluser]xwero[/eluser]
controller names isn't to difficult : APPPATH.'controllers'. But if i was you i leave the controller path up to the developers. They can either add their own path or an array of paths.

Extracting the methods is a little harder. You can read the files and regex the function names but that is going to take some time if there are a bunch of controllers.
#4

[eluser]Dave Stewart[/eluser]
[quote author="xwero" date="1215020423"]Extracting the methods is a little harder.[/quote]

Really? I was going to read the classes, load them one by one, then call a get_class_methods(). If that doesn't work within the CI structure, I'd just "new" each class.

The regexp route is also fine. The utility will only be run a couple of times, and only in development, never in production.
#5

[eluser]xwero[/eluser]
That's better Smile But i think there will be a collision if you load the controller where you call the library method in because all the classes are loaded in the global namespace. If you run the library in an independent script you shouldn't have any trouble.

More visual explanation
Code:
class a {}

class a {}
Results in an error : class a can not be redeclared.
#6

[eluser]Dave Stewart[/eluser]
Thanks for the input.

If I get what you're implying, I guess that will only happen for the controller that is actually doing the scan? I'm sure it will be fairly trivial to filter it out.

I've got some proper work to do for the rest of the day, but I'll probably have a crack tonight, and I'll post back my efforts.

Cheers!
Dave
#7

[eluser]Dave Stewart[/eluser]
As usual, I can't resist having a play (I have next to no will power) so I had a quick crack.

As it turns out, the regexp route was far more successful and flexible, as loading classes and such like created a lot of issues with classes (and previously-included classes) being redeclared.

Problem solved though!

Cheers,
Dave




Theme © iAndrew 2016 - Forum software by © MyBB