• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classes that aren't models or libraries

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?


[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 )

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?

[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.

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.

Using a classes directory sounds like a good idea. I think I'll go with that


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.