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...
By Webthink-Julian on the 1st of May 2008 02:03:43 PM
Download |
Raw |
Embed |
Report
/**
* Magic method for getting object and model keys.
*
* @param string key name
* @return mixed
*/
public function __get($key)
{
if (isset($this->object->$key))
{
return $this->object->$key;
}
//this condition doesn't need to be here but ensures we don't loop needlessly
if ( ! empty($this->object->id))
{
$foreign_table = FALSE;
foreach ($this->has_one + $this->belongs_to as $table)
{
if ( $foreign_table == FALSE AND
$table == substr ($key,0
-strlen($table)) )
{
$foreign_table = $table;
}
}
}
if ( ! empty($this->object->id) AND
$foreign_table !== FALSE )
{
// Set the model name
$model = ucfirst($foreign_table).'_Model';
// Set the child id name
$child_id = $key.'_id';
if (isset($this->object->$child_id))
{
// Get the foreign object using the key defined in this object
return $this->object->$key = new $model($this->object->$child_id);
}
else
{
// Get the foreign object using the primary key of this object
return $this->object->$key = new $model(array($this->class.'_id', $this->object->id));
}
}
else
{
switch($key)
{
case 'table_name':
return $this->table;
break;
case 'class_name':
return $this->class;
break;
case 'auto_save':
return $this->auto_save;
break;
}
}
}
Submit a correction or amendment below.
Make A New Post