Subdomain Posts
None | 12 min ago
None | 13 min ago
None | 1 hour ago
None | 3 hours ago
None | 6 hours ago
None | 6 hours ago
None | 7 hours ago
None | 10 hours ago
None | 13 hours ago
None | 19 hours ago
Recent Posts
PHP | 31 sec ago
PHP | 33 sec ago
None | 1 min ago
OCaml | 1 min ago
None | 2 min ago
None | 3 min ago
None | 4 min ago
None | 4 min ago
None | 4 min ago
None | 4 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Webthink-Julian on the 1st of May 2008 02:03:43 PM Download | Raw | Embed | Report
  1.         /**
  2.          * Magic method for getting object and model keys.
  3.          *
  4.          * @param   string  key name
  5.          * @return  mixed
  6.         */
  7.         public function __get($key)
  8.         {
  9.                 if (isset($this->object->$key))
  10.                 {
  11.                         return $this->object->$key;
  12.                 }
  13.                
  14.                 //this condition doesn't need to be here but ensures we don't loop needlessly
  15.                 if ( ! empty($this->object->id))
  16.                 {
  17.                         $foreign_table = FALSE;
  18.                         foreach ($this->has_one + $this->belongs_to as $table)
  19.                         {
  20.                                 if ( $foreign_table == FALSE AND $table == substr ($key,0-strlen($table)) )
  21.                                 {
  22.                                         $foreign_table = $table;
  23.                                 }
  24.                         }
  25.                 }
  26.                 if ( ! empty($this->object->id) AND $foreign_table !== FALSE )
  27.                 {
  28.                         // Set the model name
  29.                         $model = ucfirst($foreign_table).'_Model';
  30.  
  31.                         // Set the child id name
  32.                         $child_id = $key.'_id';
  33.  
  34.                         if (isset($this->object->$child_id))
  35.                         {
  36.                                 // Get the foreign object using the key defined in this object
  37.                                 return $this->object->$key = new $model($this->object->$child_id);
  38.                         }
  39.                         else
  40.                         {
  41.                                 // Get the foreign object using the primary key of this object
  42.                                 return $this->object->$key = new $model(array($this->class.'_id', $this->object->id));
  43.                         }
  44.  
  45.                 }
  46.                 else
  47.                 {
  48.                         switch($key)
  49.                         {
  50.                                 case 'table_name':
  51.                                         return $this->table;
  52.                                 break;
  53.                                 case 'class_name':
  54.                                         return $this->class;
  55.                                 break;
  56.                                 case 'auto_save':
  57.                                         return $this->auto_save;
  58.                                 break;
  59.                         }
  60.                 }
  61.         }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: