本文整理汇总了PHP中BaseModel::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseModel::setAttribute方法的具体用法?PHP BaseModel::setAttribute怎么用?PHP BaseModel::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseModel
的用法示例。
在下文中一共展示了BaseModel::setAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAttribute
public function setAttribute($name, $value)
{
parent::setAttribute($name, $value);
if (in_array($name, $this->attributeNames())) {
$attributes = $this->getAttributeConfigs();
$config = $attributes[$name];
// Handle special case attribute types
switch ($config['type']) {
case AttributeType::Bool:
if ($value) {
$value = (bool) $value;
}
break;
case AttributeType::Number:
if ($value) {
$value = floatval(number_format($value, $config['decimals']));
}
break;
}
$this->{$name} = $value;
return true;
} else {
return false;
}
}
示例2: setAttribute
/**
* @inheritDoc BaseModel::setAttribute()
*
* @param string $name
* @param mixed $value
*
* @return bool|null
*/
public function setAttribute($name, $value)
{
if ($name == 'plugins') {
$value = PluginUpdateModel::populateModels($value);
}
parent::setAttribute($name, $value);
}
示例3: setAttribute
/**
* @inheritDoc BaseModel::setAttribute()
*
* @param string $name
* @param mixed $value
*
* @return bool|null
*/
public function setAttribute($name, $value)
{
if ($name == 'releases') {
$value = PluginNewReleaseModel::populateModels($value);
}
parent::setAttribute($name, $value);
}
示例4: setAttribute
/**
* Any permission attribute we set needs to be boolean.
* Since Vanilla can add these columns at run time, we have to react at
* run-time.
*/
public function setAttribute($key, $value)
{
if (str_contains($key, '.') && !array_key_exists($key, $this->rules)) {
$this->getValidator()->addRule($key, 'boolean');
}
return parent::setAttribute($key, $value);
}
示例5: setAttribute
/**
* Sets an attribute's value.
*
* @param string $name
* @param mixed $value
* @return bool
*/
public function setAttribute($name, $value)
{
// Set packages as an array
if ($name == 'packages' && !is_array($value)) {
if ($value) {
$value = array_filter(ArrayHelper::stringToArray($value));
sort($value);
} else {
$value = array();
}
}
return parent::setAttribute($name, $value);
}
示例6: setAttribute
public function setAttribute($name, $value)
{
if (in_array($name, $this->attributeNames()) && $this->getAttribute($name) === $value) {
return true;
}
if (parent::setAttribute($name, $value)) {
$this->_matchedParcels = null;
$this->_matchedParcelsAtOffsets = null;
$this->_cachedIds = null;
$this->_cachedTotal = null;
return true;
} else {
return false;
}
}
示例7: setAttribute
/**
* Sets an attribute's value.
*
* In addition, clears the cached values when a new attribute is set.
*
* @param string $name
* @param mixed $value
*
* @return bool
*/
public function setAttribute($name, $value)
{
// If this is an attribute, and the value is not actually changing, just return true so the matched elements
// don't get cleared.
if (in_array($name, $this->attributeNames()) && $this->getAttribute($name) === $value) {
return true;
}
if (parent::setAttribute($name, $value)) {
$this->_matchedElements = null;
$this->_matchedElementsAtOffsets = null;
$this->_cachedIds = null;
$this->_cachedTotal = null;
return true;
} else {
return false;
}
}
示例8: setAttribute
/**
* @inheritDoc BaseModel::setAttribute()
*
* @param string $name
* @param mixed $value
*
* @return bool
*/
public function setAttribute($name, $value)
{
if ($name == 'path' && !empty($value)) {
$value = rtrim($value, '/') . '/';
}
return parent::setAttribute($name, $value);
}