ORM integration in CI questions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: ORM integration in CI questions (/showthread.php?tid=4162) |
ORM integration in CI questions - El Forum - 11-10-2007 [eluser]Unknown[/eluser] What i use currently is something like this.. Tables / fields * etc_users / id, group_id, name, password * etc_groups / id, name configuration Code: // database connection(s) setup The obj_user class Code: class obj_user extends rdp_crud { Adding a new user Code: $newuser = &$kreator->create('user'); Getting some users Code: //passing a sql query instead of an id) Getting the user with id 10 Code: $user = &$kreator->get('user',10); Assigning the user to a group Code: $group = &$kreator->get('group','WHERE `name`="root"'); Deletion of the above user Code: $user->delete(); This system just provides basic data-to-object and back transformations, while doing caching on already loaded data (only loads new or changed data from the database). I have the following classes * rdp_db (general database abstraction) * rdp_db__mysql ( mysql implementation) * rdp_crud_creator (object manager) * rdp_crud_creator__mysql (mysql-optimized) * rdp_crud (basic object) - extends into obj_user, obj_car, obj_group, etc... To integrate this with CI i have two options 1. Put everything as a library 2. Put all the object definitions (like the above-mentioned user class) in the models folder and the rest in the library Every object manager needs to be instanced only once.. and here i can do it in two ways (again ): 1. Use a function with $manager=&get;_obj_manager($name=''); which returns one of the instances (i need a $name parameter since i can have more than one) 2. Set it up in the controller with $this->dbm[$name]=&$rdp_crud after creating an instance Since CI database classes aren't meant to be extended/etc (hope i didn't read it the wrong way on the user guide), should i also use another connection to the database (with the same settings), just to be on the safe side that those two won't mess with each other? I know this is a little different from the usual mvc implementation but i think it's scalable, simple to use and extend and that`s what matters in the end. Id like your input on the best method of integration. |