News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Debuggable Blog:
How to Fetch the ENUM Options of a Field - The CakePHP Enumerable Behavior
September 08, 2009 @ 11:47:09

On the Debuggable blog, Tim Koschutzki has added a quick post looking at fetching ENUM options of a database's fields in a CakePHP application.

The field users.level is an enum type and can have the values 'guest', 'user', 'admin', 'superadmin' and 'root'. The problem is that it could be possible that new levels were added in the future. [...] So what I came up with is a very simple behavior that can extract the options for any ENUM field. It uses simple caching in order for the query to not be run all the time, so make sure to clear your cache as you update your enum field options in the db.

His code snippet creates an EnumerableBehavior for the model and grabs the column names from the given table to check the access level for each and write them out to a cache.

0 comments voice your opinion now!
cakephp framework enum option database


blog comments powered by Disqus

Similar Posts

Refulz Blog: Yii Framework - Scenarios for Conditional Multiple Validation Rules

Debuggable Blog: Summary of CakeFest #3 - Berlin

Chris Hartjes' Blog: Tutorial: Integrating PHP/SWF Charts with CakePHP

Federico Cargnelutti's Blog: Database Replication Adapter for Zend Framework Applications

Jonathan Snook's Blog: Elemental: Conditional Content with CakePHP


Community Events





Don't see your event here?
Let us know!


developer install api opinion list series threedevsandamaybe framework testing introduction symfony2 code release language interview community refactor podcast unittest laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework