Skip to content
kakra edited this page Sep 12, 2010 · 36 revisions

Since I developed with Rails using the ultra-comfortable ActiveRecord I felt the need for a similar solution in PHP. Googling around I found some people saying this is impossible. That’s true: Ruby’s OOP implementation is in many ways superior to PHP’s.

But anyway I decided: Some of ActiveRecords comfort must be possible in PHP. I’ve decided to build on AdoDB for PHP since it already does the heavy lifting of database abstraction very good.

The interface is currently very limited and should be very self explanatory - but just in case there are examples. A good source of examples can also be found in the tests directory. For all interested hackers I’ve set up a git repository here at GitHub and would be very interested on your feedback.

This project grew out of the need to ease up database development in an already existing legacy application. It’s not meant as an exact ActiveRecord replacement in PHP – just similar in convenience. Ideas go to the ideas scratchboard: Todo.

You can also follow the development on Ohloh

There’s a bug tracker at Lighthouse

Features

These are the highlight features of the current stable version:

  • Single Table Inheritance (STI): This allows you to store a class and all its ancestor classes in a single table. Just add a type column and derive your new class from the base class. The type column will be auto filled on saves and the correct class will be restored on finds.
  • Inflection framework: Property and table names are automatically set according to english inflection rules, “article” becomes many “articles”, “cow” becomes “kine”, and “sheep” stays “sheep” — the library cannot count sheep either :~).
  • Class auto-configuration: Each class automatically detects its table name and schema and configures its properties appropriate, e.g. you name your class “ArticleTag” and it will read the table “article_tags”.
  • Table associations: You can easily tell a class that is “has_many” somethings, or “belongs_to” something, and it automatically creates accessors and proxies as virtual properties.
  • It’s as easy as: class Article { function setup() { $this->has_many("tags"); } } Need to say more?

Note: With suhosin running you may need to add suhosin.executor.include.whitelist = AdoDBRecord to your php.ini.

Downloads

Development Version

Download latest tarball

  • Includes latest improvements, see changelog and take a sneak preview at Todo

Stable Versions

Download version 0.5.2b

  • Table name prefixes (by setting the table name manually in setup() method)
  • Customizable primary key name
  • Model scoping (primary to support associations in the first place)
  • Better finder interface (breaks with previous API)
  • Automatic definition of finder methods
  • Automatic definition of attribute accessor methods
  • Added associations (has_many, has_one, belongs_to in the first run – no fancy join models)
  • Deprecated _class_name() completely (it’s not and will never be PHP5 compatible)
  • Fixed destroy method with array of ids

Download version 0.4.1

  • STI (Single Table Inheritance)
  • Inflector framework
  • Inflections on table names
  • Finders supporting any count of arguments (but make no real use of it yet)
  • Testing framework: some first simple unit tests using PHP SimpleTest
  • Tested compatibility to PHP4 and PHP5 (through new testing framework)

Download version 0.3.2

  • Supports update_attributes() which updates and saves the record in one pass
  • Fixed _destroy() into destroy() (orphaned underscore from previous test implementation)
  • Checks for minimal AdoDB version requirement
  • Added prefixing AdoDB search path

Download version 0.2

  • Supports delete(), destroy() and create() methods

Download version 0.1

  • Supports deriving table from class name
  • Includes basic finders (all with where-clause and by id)
  • Includes basic save function (for create and update)

Download archived versions

Clone this wiki locally