Welcome Guest, Not a member yet? Register   Sign In
Classes that aren't models or libraries
#1

[eluser]Hypnotoad[/eluser]
I have some fairly complicated business logic which involves using several different classes. These classes are not models and I don't consider them libraries. Some of these classes may be instantiated many times within different models, so would prefer them to be instantiated manually rather than using $this->load. I'm just not sure where the best place is to store these classes. I was thinking of creating a new directory under system/application. What is considered best practice?

Thanks
#2

[eluser]Sean Gates[/eluser]
If they are classes, why wouldn't they go in the /library directory? What's your definition of the library, then?

(Totally curious, btw. Please don't take my questions as anything other than that. Thanks! Big Grin )
#3

[eluser]Hypnotoad[/eluser]
If a class is very application specific, would you consider it a library?

I suppose I could put them in the libraries directory, it just seems like the wrong place.

Is the libraries directory only meant for libraries loaded with $this->load->library? Would you consider it correct to put other classes in the library directory even though they are not used as libraries and instantiated manually within models?
#4

[eluser]Sean Gates[/eluser]
The /libraries directory should be where you put any classes you're going to use in your app, no matter where they are loaded (usually just in the controllers and models).

When you say "instantiated manually within models", can you give me some code examples? I'd like to better understand what you're asking.
#5

[eluser]WanWizard[/eluser]
Whenever you load a model or library, the loader loads these, and instantiate them.

Sometimes you need to load a PHP file that contains a class without instantiation, because you don't need the singleton pattern. Instead, you want to be able to do that manually using "new Class();".

The quickest way is the old-fashioned way: simply use "require_once" to load them. It doesn't matter where they are stored, although I prefer to store them in the 'classes' directory within the application folder.
#6

[eluser]Hypnotoad[/eluser]
Using a classes directory sounds like a good idea. I think I'll go with that

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB