Cake\ORM\Table::__call PHP Method

__call() public method

If your Table uses any behaviors you can call them as if they were on the table object.
public __call ( string $method, array $args ) : mixed
$method string name of the method to be invoked
$args array List of arguments passed to the function
return mixed
    public function __call($method, $args)
    {
        if ($this->_behaviors && $this->_behaviors->hasMethod($method)) {
            return $this->_behaviors->call($method, $args);
        }
        if (preg_match('/^find(?:\\w+)?By/', $method) > 0) {
            return $this->_dynamicFinder($method, $args);
        }
        throw new BadMethodCallException(sprintf('Unknown method "%s"', $method));
    }

Usage Example

Example #1
0
 public function __call($method, $args)
 {
     if (preg_match('/^(set|toggle)(?:[A-Z][a-z_]*)+$/', $method, $match) > 0) {
         $method = ltrim($method, $match[1]);
         $fieldName = strtolower(preg_replace('/(?<=\\w)(?=[A-Z])/', '_$1', $method));
         return $this->setField($args[0], $fieldName, !empty($args[1]) ? $args[1] : null);
     } else {
         return parent::__call($method, $args);
     }
 }