Welcome Guest, Not a member yet? Register   Sign In
ORM integration in CI questions

What i use currently is something like this..

Tables / fields
* etc_users / id, group_id, name, password
* etc_groups / id, name

// database connection(s) setup
$db = new rdp_db__mysql;

// the factory / singleton
$kreator=new rdp_crud_creator__mysql;

// other db config

// table lists (also has an auto-discovery mode)

The obj_user class
class obj_user extends rdp_crud {
    function set_name($text)

    function set_password($text)
    // on object load
    function __init()
    // on delete - true if can be deleted, false if not
    function __delete()
            return false;
        } else {
            return true;

Adding a new user
$newuser = &$kreator->create('user');
$newuser->set_name('some random name');

Getting some users
//passing a sql query instead of an id)
$userlist=&$kreator->get('user','WHERE `name` LIKE `a%`');
for($i=0, $maxi=count($userlist)-1;$i<=$maxi;$i++)
  echo $i,'<b>',$userlist[$i]->data['name'].'</b><br>';

Getting the user with id 10
$user = &$kreator->get('user',10);

Assigning the user to a group
$group = &$kreator->get('group','WHERE `name`="root"');

// simple linkage

// or you can create multiple types of links between objects
// suppose $car is a car object,
$user->link_to($car, 'owner');
$user->link_to($car, 'driver');

Deletion of the above user

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 Wink):
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.

Theme © iAndrew 2016 - Forum software by © MyBB