Welcome Guest, Not a member yet? Register   Sign In
Outlet ORM
#1

[eluser]fgrehm[/eluser]
Hy guys,

I've been using this really cool ORM library called Outlet and I'd like to share how I managed to integrate it on CI. Since it is my first contribution to the community, just let me know if I'm doing anything wrong or forgetting something here.
Since english is not my native language, sorry about any incorrect use of words or mispelling.

--------------------------------------------------------------------------

Here is the site and documentation. For this post, I'm going to assume that you've created your models and config file needed to get the libray working.

This is the folder structure I built:
Code:
../application/config
    - outlet-config.php

../application/models
    - models_include.php // file to include models
    - ... models ...

../application/outlet
    - ... library files ...

../application/libraries
    - MY_Loader.php // Extends CI loader and adds a new method to load Outlet

To load the library, I extended CI loader and added this method
Code:
class MY_Loader
    function outlet()
    {
        static $loaded = false;
        if ($loaded) return;
        
        // Includes models
        include_once APPPATH.'/models/models_include.php';
                
        // Sets outlet include path
        ini_set('include_path', ini_get('include_path').';'.realpath(APPPATH.'/outlet'));
        require_once 'Outlet.php';
          
        Outlet::init(include APPPATH.'/config/outlet-config.php');
    
        $outlet = Outlet::getInstance();
        $outlet->createProxies();
        $loaded = true;
    }
}

And to avoid name conflicts, I did a small change to the /system/codeigniter/CodeIgniter.php so that all controllers will need the 'Controller' suffix
Code:
....
/*
* ------------------------------------------------------
*  Security check
* ------------------------------------------------------
*  ...
*/
$class  = $RTR->fetch_class().'Controller'; // Here is the change
$method = $RTR->fetch_method();


if ( ! class_exists($class)
    OR $method == 'controller'
...

I did that so that I can have a Order entity, an OrderController and still use a clean URL /index.php/order without any change to the CI core


I'm actually using the repository pattern but to make things simple, here's a sample usage:
Code:
class OrderController extends Controller
{
    function show($id)
    {
        $this->load->outlet();
        
        $outlet = Outlet::getInstance();
        $order = $outlet->load('Order', $id);
        // display order data...
    }
}

The 'models_include.php' file is really simple:
Code:
/**
* Include all models
*/

require_once 'Order.php';
require_once 'OrderLine.php';
// ... other entities ...

I hope you guys like it

--
Fábio Rehm


Messages In This Thread
Outlet ORM - by El Forum - 10-31-2008, 12:42 PM
Outlet ORM - by El Forum - 11-03-2008, 02:05 PM
Outlet ORM - by El Forum - 03-12-2009, 10:05 AM
Outlet ORM - by El Forum - 03-13-2009, 12:10 PM
Outlet ORM - by El Forum - 04-22-2009, 08:56 AM
Outlet ORM - by El Forum - 10-28-2009, 08:54 AM
Outlet ORM - by El Forum - 10-29-2009, 04:04 PM
Outlet ORM - by El Forum - 11-17-2009, 03:55 AM
Outlet ORM - by El Forum - 11-17-2009, 05:13 AM
Outlet ORM - by El Forum - 11-17-2009, 08:39 AM
Outlet ORM - by El Forum - 11-17-2009, 02:43 PM
Outlet ORM - by El Forum - 11-18-2009, 01:47 AM
Outlet ORM - by El Forum - 11-25-2009, 01:16 PM
Outlet ORM - by El Forum - 07-08-2010, 08:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB