11.20 php saved
jose_zap
Tags add more
lazy loading model a  
Note
Lazy loading for model associations
  1.     function __get($assoc) {
  2.         foreach ($this->__associations as $type) {
  3.             if(array_key_exists($assoc, $this->{$type})) {
  4.                 parent::__constructLinkedModel($assoc, $this->{$type}[$assoc]['className']);
  5.             }
  6.            
  7.             parent::__generateAssociation($type);
  8.         }
  9.        
  10.         return $this->{$assoc};
  11.     }
  12.    
  13.    
  14.     function __isset($assoc) {
  15.         if(isset($this->{$assoc})) {
  16.             return true;
  17.         } else {
  18.             //Try loading a model
  19.             foreach ($this->__associations as $type) {
  20.                 if(array_key_exists($assoc, $this->{$type})) {
  21.                     parent::__constructLinkedModel($assoc, $this->{$type}[$assoc]['className']);
  22.                 }
  23.                
  24.                 parent::__generateAssociation($type);
  25.             }
  26.            
  27.             return isset($this->{$assoc});
  28.         }
  29.     }
  30.    
  31.     function __constructLinkedModel($assoc, $className = null) {
  32.         foreach ($this->__associations as $type) {
  33.             if(array_key_exists($assoc, $this->{$type})) {
  34.                 return;
  35.             }
  36.         }
  37.        
  38.         parent::__constructLinkedModel($assoc, $className);
  39.     }
Parsed in 0.044 seconds, using GeSHi 1.0.7.14

Modify this Paste