I was wondering what should I do with my entities? For example, a class named Articles, with a few datamembers (name/title/date) and getters & setters. I could add these to my Articles datamember, but it's better practice to seperate those. So what do you think?
Thanks!
i usually do this:
1.- create my entity classes in /system/application/classes
2.- define a constant to point to that folder on /system/application/config/constants.php
3.- include the entities classes from the models:
That won't break your mvc structure, and keeps for entities classes separated. Hope that helps!
I liked @ilbesculpi's solution, but I customized it a bit using a namespace rather than using a constant and
require_once
. Here is my version:1) Create my entity classes in /system/application/entities.
2) Include my entity class in my model via a
using
statement.CodeIgniter models use the singleton pattern. You can create libraries or use $foo = new Some_Model if you like, remember that its all just PHP :)