Creating custom attributes: Difference between revisions
Appearance
Despam |
|||
| Line 31: | Line 31: | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
class | class clickableLabelAttribute extends atkAttribute | ||
{ | { | ||
function getLabel() | function getLabel() | ||
Revision as of 01:17, 15 April 2008
|
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 clickableLabelAttribute 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..