think\Model::__call PHP Method

__call() public method

public __call ( $method, $args )
    public function __call($method, $args)
    {
        $query = $this->db();
        if (method_exists($this, 'scope' . $method)) {
            // 动态调用命名范围
            $method = 'scope' . $method;
            array_unshift($args, $query);
            call_user_func_array([$this, $method], $args);
            return $this;
        } else {
            return call_user_func_array([$query, $method], $args);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * 利用__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);
     }
 }
All Usage Examples Of think\Model::__call