I was browsing SO and found this hosted code as a recommended way of cutting down on PHP code.
https://github.com/jamierumbelow/codeigniter-base-model
So far, from the methods that I have figured out how to use, I love what it does and how simple it makes things.
However, in the following code:
/**
* Get a single record by creating a WHERE clause by passing
* through a CI AR where() call
*
* @param string $key The key to search by
* @param string $val The value of that key
* @return object
*/
public function get_by() {
$where =& func_get_args();
$this->_set_where($where);
$this->_run_before_get();
$row = $this->db->get($this->_table)
->row();
$this->_run_after_get($row);
return $row;
}
I’m not exactly sure how to make a call to this function.
The description of what it does is exactly what I want to do.
The @params say it takes in a key and value pair for the WHERE block but I don’t see any function inputs in the method signature.
Help, please?
As I’m noticing with a lot of CI code, it’s strange and maintenance un-friendly.
PHP functions can accept n or more arguments (where n is the number of arguments defined in the signature)
The code makes use of
func_get_args()which returns an array of arguments.The array of arguments is then passed to the
_set_where()method which passes either one or two items to thedb->where()method.A more descriptive method signature would have been