public
Description: MIT licensed code without warranty ; )
Homepage: http://www.debuggable.com/
Clone URL: git://github.com/felixge/debuggable-scraps.git
name age message
..
file lookupable.php Sat Aug 30 05:15:00 -0700 2008 Initial Lookupable release [Felix Geisendörfer]
file readme.textile Sat Aug 30 05:15:00 -0700 2008 Initial Lookupable release [Felix Geisendörfer]
cakephp/behaviors/lookupable/readme.textile

CakePHP Lookupable Behavior

A CakePHP behavior to easily look up the id’s of records or create them if they do not exist yet. Useful when working with lots of lookup / status tables.

Installing

1. Copy lookupable.php to app/models/behaviors/
2. Open / create app/app_model.php and add the following:


class AppModel extends Model{
	var $actsAs = array('Lookupable');
}

Usage / Docs

To lookup the id of lets say your ‘Admin’ group, you can simply do:


$group_id = $this->Group->lookup('Admin');

If the group does not exist yet, the behavior will automatically create it and return the id of the newly created record.

Known Bugs

None