Skip to content

Commit

Permalink
Added __call() magic method to fuel_category_model so it will return …
Browse files Browse the repository at this point in the history
…the model object if get_{module}(TRUE) is used
  • Loading branch information
David McReynolds committed Nov 5, 2014
1 parent f714a6f commit be591bb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fuel/modules/fuel/models/fuel_categories_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ public function get_children($where = array(), $order = NULL, $limit = NULL, $of

// --------------------------------------------------------------------

/**
* Magic method that will allow you to return the model object by doing something like $cateogry->get_products(TRUE);
*
* @access public
* @param string field name
* @param array arguments
* @return mixed
*/
public function __call($method, $args)
{
if (preg_match("/^get_(.*)/", $method, $found))
{
$model = $this->get($found[1]);
if ($model)
{
$data = (isset($args[0]) AND $args[0] === TRUE) ? $model : $model->find_all();
return $data;
}
}
return parent::__call($method, $args);
}

// --------------------------------------------------------------------

/**
* Magic method to return first property, method, then field values
*
Expand Down

0 comments on commit be591bb

Please sign in to comment.