Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2007, 08:46 AM
Junior Member
 
Join Date: Jun 2007
Posts: 8
Default Placement of generic functions / helpers for models

Hi,

I've got a number of models defined in my application. In each model I have the function:

PHP Code:
function generateOptionsFromMeta() {

    
$enumList = Array();

    foreach(
$this->_metadata AS $fieldName => $fieldAttributes) {
    
        if(
'enum' == substr($fieldAttributes['DATA_TYPE'],0,4)) {
        
            foreach(eval(
'return '.str_replace('enum''Array'$fieldAttributes['DATA_TYPE'].';')) AS $key => $value) {
            
                
$enumList[$fieldName][$value] = $value;
            }
        }
    }
    
    return(
$enumList);

Obviously this needs re-factoring, where can I place these types of functions that are usable on every model without modification?

Thanks

Andrew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-08-2007, 05:00 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

Extend Zend_Db_Table_Abstract, add your function, now all models extend your extended Zend_Db_Table_Abstract
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-08-2007, 12:57 PM
Junior Member
 
Join Date: Jun 2007
Posts: 8
Default

Perfect, thank you.

Andrew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:47 PM.