Creating custom attributes: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting | Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting | ||
< | |||
<syntaxhighlight lang="php"> | |||
useattrib("yourmodule.yourattrib"); | useattrib("yourmodule.yourattrib"); | ||
</ | </syntaxhighlight> | ||
in the node file. If you do that, in the node constructor it's only a matter of: | in the node file. If you do that, in the node constructor it's only a matter of: | ||
< | |||
<syntaxhighlight lang="php"> | |||
$this->add(new yourCustomAttribute(.......)); | $this->add(new yourCustomAttribute(.......)); | ||
</ | </syntaxhighlight> | ||
==Display override== | ==Display override== | ||
< | |||
<syntaxhighlight lang="php"> | |||
class boldAttribute extends atkAttribute | class boldAttribute extends atkAttribute | ||
{ | { | ||
| Line 21: | Line 26: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
==Custom label== | ==Custom label== | ||
< | |||
<syntaxhighlight lang="php"> | |||
class clickableLableAttribute extends atkAttribute | class clickableLableAttribute extends atkAttribute | ||
{ | { | ||
| Line 33: | Line 40: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
==Edit override== | ==Edit override== | ||
| Line 41: | Line 49: | ||
Converting data right before it goes in the db, or right after it's loaded from the db: | Converting data right before it goes in the db, or right after it's loaded from the db: | ||
< | |||
<syntaxhighlight lang="php"> | |||
class encryptedAttribute extends atkAttribute | class encryptedAttribute extends atkAttribute | ||
{ | { | ||
| Line 58: | Line 67: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
==Custom load/save== | ==Custom load/save== | ||
todo.. | todo.. | ||
Revision as of 15:17, 14 January 2007
|
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..