예제 #1
0
 public function flush()
 {
     // empty cache
     MCache::instance()->delete_all();
     // back to start
     url::redirect('cormdemo/index');
 }
예제 #2
0
 /**
  * Handles retrieval of all model values, relationships, and metadata.
  *
  * @param   string  column name
  * @return  mixed
  */
 public function __get($column)
 {
     if (array_key_exists($column, $this->object)) {
         return $this->object[$column];
     } elseif (isset($this->related[$column])) {
         return $this->related[$column];
     } elseif ($column === 'primary_key_value') {
         return $this->object[$this->primary_key];
     } elseif ($column === 'db') {
         // lazy loading of DB
         if (!is_object($this->_db)) {
             $this->_db = Database::instance($this->_db);
         }
         return $this->_db;
     } elseif ($column === 'cache') {
         // lazy loading of cache
         if (!is_object($this->_cache)) {
             $this->_cache = MCache::instance($this->_cache);
         }
         return $this->_cache;
     } elseif (isset($this->sets[$column])) {
         // custom set
         $object_name = $this->sets[$column]['object_name'];
         $id_set = $this->get_relations($column);
         // custom sets are stored in the related array
         //return $this->related[$column] = $this->get_set($object_name,$id_set);
         return $this->related[$column] = new CORM_Iterator($object_name, $id_set);
     } elseif (in_array($column, $this->has_one) || in_array($column, $this->belongs_to) || in_array($column, $this->has_many) || in_array($column, $this->has_and_belongs_to_many)) {
         // relationship
         $object_name = in_array($column, $this->has_many) || in_array($column, $this->has_and_belongs_to_many) ? inflector::singular($column) : $column;
         $id_set = $this->get_relations($column);
         //return $this->related[$column] = $this->get_set($object_name,$id_set);
         return $this->related[$column] = is_array($id_set) ? new CORM_Iterator($object_name, $id_set) : CORM::factory($object_name, $id_set);
     } elseif (isset($this->ignored_columns[$column])) {
         return NULL;
     } elseif (in_array($column, array('object_name', 'object_plural', 'primary_key', 'primary_val', 'table_name', 'table_columns', 'loaded', 'saved', 'has_one', 'belongs_to', 'has_many', 'has_and_belongs_to_many', 'load_with', 'cachable', 'expire'))) {
         // Model meta information
         return $this->{$column};
     } else {
         throw new Kohana_Exception('core.invalid_property', $column, get_class($this));
     }
 }