EllisLab text mark
Advanced Search
     
Outlet ORM
Posted: 31 October 2008 03:42 PM
Joined: 2007-10-18
9 posts

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:

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

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

....
/*
 * ------------------------------------------------------
 *  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:

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:

/**
* Include all models
*/

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

I hope you guys like it


Fábio Rehm

 
Posted: 03 November 2008 04:05 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-10-18
9 posts

For those using HMVC you have to modify the Loader inside the Controller.php file.


See ya,

Fábio Rehm

 
Posted: 12 March 2009 01:05 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-02-16
3 posts

What is your experience with this ORM?

Is it stable enough for production environments?

Any significant performance issues?

many thanks for sharing your solution

 
Posted: 13 March 2009 03:10 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2007-10-18
9 posts

Hi acpbl,

I haven’t used it on production enviroments yet but I’m about to launch an intranet that uses it.
I’m currently helping the library development and I can say that the main developer (Alvaro Carrasco) has been using it on production.

The thing to watch out for is changes to the API, since it hasn’t reached 1.0 it is still evolving.


Feel free to test the library and join us on Google Groups if you have any other questions.
http://groups.google.com/group/outlet-orm

Fabio Rehm

 
Posted: 22 April 2009 11:56 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2007-10-18
9 posts

Hi Guys,

I’m just dropping by to say that the 0.7 version of the library was released.

These are the new features:
  * One-to-one and many-to-many relationships
  * PHP-5.2’s DateTime support
  * Fluent-interface query API
  * Eager-fetching
  * PostgreSQL support

Check it out:
  http://www.outlet-orm.org/

Regards,

Fabio Rehm

 
Posted: 28 October 2009 11:54 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-04
534 posts

This looks very interesting.

I also have to say I like your change to codeigniter.php to force controllers to end in Controller while not indicating this in the url. This would be a great permanent change.

 
Posted: 29 October 2009 07:04 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2007-10-18
9 posts

I’m glad that you’ve liked it grin

We’ve been working on the 2.0 version on Github, there are some cool new features like Unit of Work and proxy caching. Just keep in mind that it is on a really early stage and it need to implement some features that we currently support on 0.7:
  http://github.com/fgrehm/outlet-orm

If you have any questions you can drop by our group:
  http://groups.google.com/group/outlet-orm


Regards,

Fábio Rehm

 
Posted: 17 November 2009 05:55 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-11
560 posts

This looks very interesting. It seems pretty similar to Doctrine though, how does it compare? From the docs it seems it handles relationships nicely grin

 Signature 

bybjorn.com: ExpressionEngine Freelancer - Premium ExpressionEngine 2.0 Themes - WDA: ExpressionEngine Add-ons - contact me on twitter: twitter.com/bjornbjorn - Zerply profile: zerp.ly/bjornbjorn

 
Posted: 17 November 2009 07:13 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-11
560 posts

Ok, just a little update, fgrehm answered my question on Twitter:

* well, Doctrine < 2.0 is more like activerecord pattern and outlet like data mappers
* doctrine has more features than outlet but that actually makes us easier to use and give us better performance (never measured)
* and doctrine 2.0 query language is a lot verbose, they require u to use fully qualified class names, outlet supports aliasing
* aliasing stuff relates to outlet 2.0 version still being developed on http://is.gd/4WXK7

 Signature 

bybjorn.com: ExpressionEngine Freelancer - Premium ExpressionEngine 2.0 Themes - WDA: ExpressionEngine Add-ons - contact me on twitter: twitter.com/bjornbjorn - Zerply profile: zerp.ly/bjornbjorn

 
Posted: 17 November 2009 10:39 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-04
72 posts

I like the fact that Outlet doesn’t require your objects to be extended.

Also for being lightweight, it sure is faster than Doctrine?

 Signature 

Programming is both a science and an art.
——
http://twitter.com/MarcoBarbosa
http://marcobarbosa.com

 
Posted: 17 November 2009 04:43 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2007-10-18
9 posts

@bjornbjorn
  Thanks for posting my reply here :D

@M4rc0
  I can’t tell you 100% that it is faster and how faster it is. The fact that we use plain PDO and that we are not using reflection makes me believe in it. I know that have a PECL extension that does the hydration using C code but I’ve never tried it.

If anyone is interested in doing this benchmark don’t forget to show us the results :D

Regards,

Fábio Rehm

 
Posted: 18 November 2009 03:47 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-29
344 posts

How does this compare to Datamapper OverZelous edition?

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger :: DB Configs

 
Posted: 25 November 2009 03:16 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-04
72 posts
fgrehm - 31 October 2008 07:42 PM

I’m actually using the repository pattern but to make things simple, here’s a sample usage:

class OrderController extends Controller
{
    
function show($id)
    
{
        $this
->load->outlet();
        
        
$outlet Outlet::getInstance();
        
$order $outlet->load('Order'$id);
        
// display order data...
    
}

Hi (Olá) Fábio,

Could you elaborate your example a little bit further?

You gave a great introduction to Outlet, and that is the problem because I’m more interested now (also searching for an ORM) smile

How would the model look like in this “repository” pattern? Is this the same as a “Domain Driven Design” pattern?

I’m just trying to imagine the model after you presented the controller smile

 Signature 

Programming is both a science and an art.
——
http://twitter.com/MarcoBarbosa
http://marcobarbosa.com

 
Posted: 08 July 2010 11:37 PM   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-08-28
1 posts
M4rc0 - 25 November 2009 08:16 PM

How would the model look like in this “repository” pattern? Is this the same as a “Domain Driven Design” pattern?

I’m just trying to imagine the model after you presented the controller smile

This is how I would do it. I was taught that all DB calls are done in the model. The controller and views should not have to request anything from the DB. Might not be the best way, but it works for me. 

class OrderController extends Controller
{
    
function show($id)
    
{
  
        
// display order data...
        
$data['order'$this->order_model->getOrderById($id);
        
$this->load->view('showOrder'$data);
    
}
}

// in the model file Order_model.php
class order_model extends Model
{
     
function getOrderById($id)
     
{
        $this
->load->outlet();
        
        
$outlet Outlet::getInstance();
        
$order $outlet->load('Order'$id);
        
        
// Normally, I'd validate to make sure I have something to return
        
return $order;
     
}