Creating custom attributes
Appearance
|
ATK Howto: Creating custom attributes
|
There are many ways in which attributes can be extended. Below are a few examples of attributes that extend other attributes, but add some logic.
Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting
useattrib("yourmodule.yourattrib");
in the node file. If you do that, in the node constructor it's only a matter of:
$this->add(new yourCustomAttribute(.......));
Display override
class boldAttribute extends atkAttribute
{
function display($record, $mode="")
{
$org = parent::display($record, $mode);
return '<b>'.$org.'</b>';
}
}
Custom label
class clickableLableAttribute extends atkAttribute
{
function getLabel()
{
$label = parent::getLabel();
$url = "http://www.achievo.org/atk";
return href($url, $label);
}
}
Edit override
todo..
Data conversion
Converting data right before it goes in the db, or right after it's loaded from the db:
class encryptedAttribute extends atkAttribute
{
function value2db($record)
{
$value = parent::value2db($record);
$value = someEncryptionMethod($value);
return $value;
}
function db2value($record)
{
$value = parent::db2value($record);
$value = someDescryptionMethod($value);
return $value;
}
}
Custom load/save
todo..
Original Poster: Ivo