/** * * 利用__call方法重载 实现一些特殊的Model方法 (魔术方法) * * @access public * * @param string $method 方法名称 * @param mixed $args 调用参数 * * @return mixed * */ public function __call($method, $args) { if (strtolower(substr($method, 0, 3)) == 'top') { // 获取前N条记录 $count = substr($method, 3); array_unshift($args, $count); return call_user_func_array(array(&$this, 'topN'), $args); } else { return parent::__call($method, $args); } }
/** * * 动态方法实现 * * @access public * * @param string $method 方法名称 * @param array $args 调用参数 * * @return mixed * */ public function __call($method, $args) { if (strtolower(substr($method, 0, 8)) == 'relation') { $type = strtoupper(substr($method, 8)); if (in_array($type, array('ADD', 'SAVE', 'DEL'), true)) { array_unshift($args, $type); return call_user_func_array(array(&$this, 'opRelation'), $args); } } else { return parent::__call($method, $args); } }