本文整理汇总了PHP中ActiveRecord::__set方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::__set方法的具体用法?PHP ActiveRecord::__set怎么用?PHP ActiveRecord::__set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::__set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __set
public function __set($name, $value)
{
if (in_array($name, $this->i18n())) {
$attr = Yii::app()->language . '_' . $name;
$this->{$attr} = $value;
} else {
parent::__set($name, $value);
}
}
示例2: __set
/**
* Magic method for setting properties.
*/
public function __set($name, $value)
{
switch ($name) {
case 'name':
$value = trim($value);
if (strlen($value) < self::MIN_USERNAME_LENGTH) {
// Usage of strlen() intentional for unicode characters
throw new ErrorException('Username should be at least ' . self::MIN_USERNAME_LENGTH . ' characters.');
}
if (mb_strlen($value) > self::MAX_USERNAME_LENGTH) {
throw new ErrorException('Username may not exceed ' . self::MAX_USERNAME_LENGTH . ' characters.');
}
if (SessionUser::IllegalUsername($value)) {
throw new ErrorException('Username is reserved. Please choose another username.');
}
try {
$class = get_called_class();
$user = $class::FindByName($value);
throw new ErrorException('Username already exists. Please choose another username.');
} catch (ActiveRecord_NotFoundException $e) {
// "Not Found" is the desired result
}
parent::__set($name, $value);
break;
case 'password':
throw new ErrorException('Use <i>SetPassword()</i> to change password.');
case 'email':
if (!empty($value)) {
$value = filter_var($value, FILTER_VALIDATE_EMAIL);
if ($value == false) {
throw new ErrorException('Email address is not valid. Please check if you entered it correctly.');
}
// Check if email host actually exists (parse_url() is faked into thinking email address is URL to get hostname)
$parts = parse_url('http://' . $value . '/');
if (!isset($parts['host']) || filter_var($parts['host'], FILTER_VALIDATE_IP) == false && gethostbyname($parts['host']) == $parts['host']) {
throw new ErrorException('Your email host <i>' . SafeHTML($parts['host']) . '</i> does not appear to exist.');
}
parent::__set($name, $value);
}
break;
default:
parent::__set($name, $value);
}
}
示例3: __set
/**
* Запрет менять type
*
* @param type $name
* @param type $value
* @throws Exception
*/
public function __set($name, $value)
{
if ($name == 'type') {
throw new Exception('Запрещено менять тип записей');
} else {
parent::__set($name, $value);
}
}
示例4: __set
/**
* Magic method for setting properties.
*/
public function __set($name, $value)
{
switch ($name) {
case 'post_date':
if ($value > time()) {
$this->changes[$name] = time();
} else {
$this->changes[$name] = $value;
}
break;
default:
parent::__set($name, $value);
}
}