Welcome Guest, Not a member yet? Register   Sign In
Autoloading models and libraries
#1

[eluser]TheFuzzy0ne[/eluser]
I was toying with the idea of adding a __get() method to the controller class, and see if I could get libraries and models to autoload as they were called. When I considered subdirectories, it became apparent that this might not be as useful as I had originally hoped. I just wanted to hear anyone else's thoughts on the subject. Would this be useful or useless?
#2

[eluser]slowgary[/eluser]
Sounds like a lot of extra work just to be lazy ;-P. I'm don't know what it would entail, but it might be useful. What type of overhead would it add though? I'm not sure I would need it, as I'm still chipping away at my understanding of CI and thus only use a few classes so far.

If it works with minimal overhead, maybe they'd add it to the base. It would just make CI that much easier.
#3

[eluser]TheFuzzy0ne[/eluser]
The overhead should be minimal. I was thinking of naming all models with a _model prefix (as I do now), and if it doesn't have a _model, to try and load a library. Of course, none of the above happens if the requested property already exists. I've been thinking a bit further into it, and I can't help thinking that the idea itself is novel, but there's not much in the way of consistency, as you can't load helpers/plugins in the same fashion. If all helper functions started with the helper name i.e. forum_get_menu(), array_search() and so on, then this would be possible. With that said, it's not terribly difficult to just load whatever you need anyway, I just thought it might have potential.
#4

[eluser]Dam1an[/eluser]
2 potential problems come to mind (well, one problem in 2 differant scenarios)

1. Aliasing models? How would that work
2. Passing config setting to a library?
#5

[eluser]xwero[/eluser]
3. make libraries known in models

Now everything is controlled by the loader class. By using the magic get method you split up the responsibility.

If you consider an alternative way of autoloading i suggest the autoload magic function.
#6

[eluser]TheFuzzy0ne[/eluser]
Dam1an, perhaps this information could be kept in a config file of sorts?

I can look into that, the main reason I posted was to see if it interested anyone, or if the general consensus was that it might be a waste of time.




Theme © iAndrew 2016 - Forum software by © MyBB