05.02 php saved
Lion30
Tags add more
AppModel, automagic and conditions  
Note
Insert into your appModel if you have a field like lang_code in several DB tables and you would like to add automagically a wanted condition to all your queries on the tables that have this field
  1.     function beforeFind($queryData){
  2.         if(isset($this->_schema['lang_code'])){
  3.             if(!empty($queryData['conditions'])){
  4.                 if(is_array($queryData['conditions'])){
  5.                     $queryData['conditions'][] = $this->alias.".lang_code = '".SL."'";
  6.                 }else{
  7.                     $cond = array($queryData['conditions'], $this->alias.".lang_code = '".SL."'");
  8.                     $queryData['conditions'] = $cond;
  9.                 }
  10.             }else{
  11.                 $queryData['conditions'] = $this->alias.".lang_code = '".SL."'";
  12.             }
  13.         }
  14.        
  15.         return $queryData;
  16.     }
Parsed in 0.048 seconds, using GeSHi 1.0.7.14

Modify this Paste