pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

kohana private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Shadowhand on Thu 1 May 16:08 (modification of post by Webthink-Julian view diff)
report abuse | download | new post

  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 (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post