__call() public method

In this case we are attempting to convert camel case formatted methods into underscore formatted methods. This allows us to call methods using camel case and remain backwards compatible.
public __call ( string $name, array $arguments ) : boolean | ORMWrapper
$name string
$arguments array
return boolean | ORMWrapper
Example #1
0
 /**
  * 魔术方法用于动态执行Db类中的方法
  * @param $method
  * @param $param
  * @return mixed
  */
 public function __call($method, $param)
 {
     if (in_array($method, $this->queryMethod)) {
         $this->setDriverOption();
     }
     /**
      * 调用父类方法完成查询操作
      */
     return parent::__call($method, $param);
 }
 /**
 +----------------------------------------------------------
 * 利用__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);
     }
 }
Example #4
0
 public function notUsedCall($method, $params)
 {
     // Notice (8): Undefined index: Id [CORE/Cake/Model/Model.php, line 2673]
     // Notice (8): Undefined index: Id [CORE/Cake/Model/Model.php, line 2650]
     if (strpos($method, 'findBy') === 0) {
         debug($method);
         parent::__call($method, $params);
         debug($methodArgs);
     }
     if (strpos($method, 'generateAllFor') === 0) {
         // massage the args
         $methodArgs = $params;
         $methodArgs[0] = str_replace('generateAllFor', '', $method);
         // TODO
         //array_unshift($methodArgs, str_replace('generateAllFor', '', $method));
         // do the actual call
         return call_user_func_array(array($this, 'generateAllFor'), $methodArgs);
     }
     return false;
 }