本文整理汇总了PHP中AssetFileModel::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetFileModel::setAttribute方法的具体用法?PHP AssetFileModel::setAttribute怎么用?PHP AssetFileModel::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetFileModel
的用法示例。
在下文中一共展示了AssetFileModel::setAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: craft
/**
* Magic getter
*
* @param string $name
* @return mixed
*/
function __get($name)
{
// Is it a transform handle?
$transform = craft()->assetTransforms->getTransformByHandle($name);
if ($transform) {
// Duplicate this model and set it to that transform
$model = new AssetFileModel();
// Can't just use getAttributes() here because we'll get thrown into an infinite loop.
foreach ($this->attributeNames() as $attributeName) {
$model->setAttribute($attributeName, parent::getAttribute($attributeName));
}
$model->setTransform($transform);
return $model;
} else {
return parent::__get($name);
}
}
示例2: __get
/**
* Magic getter
*
* @param string $name
*
* @throws \Exception
* @return mixed
*/
public function __get($name)
{
// Run through the BaseModel/CModel stuff first
try {
return parent::__get($name);
} catch (\Exception $e) {
// Is $name a transform handle?
$transform = craft()->assetTransforms->getTransformByHandle($name);
if ($transform) {
// Duplicate this model and set it to that transform
$model = new AssetFileModel();
// Can't just use getAttributes() here because we'll get thrown into an infinite loop.
foreach ($this->attributeNames() as $attributeName) {
$model->setAttribute($attributeName, parent::getAttribute($attributeName));
}
$model->setContent($this->getContent());
$model->setTransform($transform);
return $model;
}
// Fine, throw the exception
throw $e;
}
}