CodeIgniter – GAS ORM

CodeIgniter comes with an ActiveRecord implementation that is fairly straightforward. You can retrieve table rows easily, but you have to write your own logic if you need an extra layer of abstraction (models). Models can help for example to traverse relationships between entities easily, by lazy or eager-loading related entites when they are needed.

There are many PHP ORMs available that provide this abstraction, but none of them integrates nicely with CodeIgniter’s ActiveRecord. At least, I could find any.

I was looking for an ORM that:

  • is a layer on top of CodeIgniter’s ActiveRecord implementation. I don’t like importing a large 3th party library like Doctrine into my CodeIgniter projects, and trick CodeIgniter into using that instead of its own databases access layer.
  • Provides freedom in how and when to use it. I like the idea of convention over configuration, but in real world situations, using a framework that enforces too strict can be a burden. For example when using a legacy database.

Enter GAS ORM. Gas ORM is an excellent initiative by a single developer: Taufan Adity. GAS can be mixed with ActiveRecord calls, and supports convention as well as configuration. On top of that, the developer welcomes requests and questions. If you want to make handling database access with CodeIgniter easier: try it!

Gas code example:

$this->load->library('gas');
// to see available models :
// var_dump($this->gas->list_models());
$user = new User;

// Now you can use any available Gas method, or your User models public method

$user1 = $user->find(1);

$user1 = Gas::factory('user')->find(1);

I haven’t tested GAS extensively yet though, but the first version looks very promising.

Links

One Response to “CodeIgniter – GAS ORM”

  1. Nice article. Thanks for posting.

Leave a Reply





Human Verification