本文整理匯總了PHP中Phalcon\Mvc\Model::__set方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::__set方法的具體用法?PHP Model::__set怎麽用?PHP Model::__set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\Model
的用法示例。
在下文中一共展示了Model::__set方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __set
public function __set($fieldName, $value)
{
// Check if the property is public
try {
$R = new \ReflectionClass($this);
$property = $R->getProperty($fieldName);
} catch (\ReflectionException $e) {
// Property doesn't exist, call the stupid parent
return parent::__set($fieldName, $value);
}
if ($property->isPublic()) {
// Again, call your parents
return parent::__set($fieldName, $value);
} else {
// Property exists, and it's private / protected
try {
// Maybe there is a setter for this one?
$nameArr = explode('_', $fieldName);
$methodName = 'set';
foreach ($nameArr as $vv) {
$methodName .= ucwords($vv);
}
$method = $R->getMethod($methodName);
// Okay, no exception, let's call it
return $this->{$methodName}($value);
} catch (\ReflectionException $up) {
// Just let it go through
throw $up;
}
}
}
示例2: __set
public function __set($property, $value)
{
if (is_object($property) || is_array($property)) {
return parent::__set($property, $value);
}
$this->_dataAccess[$property] = $value;
}
示例3: __set
/**
* Magic method to use attribute in snake_case
* For example $ex->a_method = $value is same as $ex->setAMethod($value)
* @param string $property The property in snake_case
* @param array $params The value that will be passed to set method
* @return mixed Call the method if it exists, otherwise call parent __set() method
*/
public function __set($property, $params)
{
$method = 'set' . Phalcon\Text::camelize($property);
if (method_exists($this, $method)) {
return $this->{$method}($params);
}
parent::__set($property, $params);
}