AtkDummyAttribute: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
{{attribute}} | {{attribute}} | ||
The atkDummyAttribute can be used to add arbitrary text/html to a form. It's called 'dummy' because it's an attribute that is not persisted in the database in any way. | |||
= Basic usage = | |||
Using an atkDummyAttribute is fairly easy. Just add it to a node and pass the desired text as the second parameter. | |||
<syntaxhighlight lang="php"> | |||
$this->add(new atkDummyAttribute("explanation", "Enter your mother's maiden name in the below field only if your mother agrees")); | |||
</syntaxhighlight> | |||
Note that dummy attributes by default do not have a label (as its regular usecase normally doesn't require one). In the occasion that you do want the label to be visible, you can add the [[Attribute flags|attribute flag]] AF_DUMMY_SHOW_LABEL. | |||
A slightly more sophisticated version of the atkDummyAttribute is the [[atkParserAttribute]]. It has the same api, but features the substitution of template variables in the text. | |||
= Advanced usage = | |||
it is possible to use this attribute among other things to give a dynamic non edit field. a none dynamic string from other attributes should use [[atkParserAttribute]] instead. | it is possible to use this attribute among other things to give a dynamic non edit field. a none dynamic string from other attributes should use [[atkParserAttribute]] instead. | ||
Revision as of 21:42, 18 August 2008

The atkDummyAttribute can be used to add arbitrary text/html to a form. It's called 'dummy' because it's an attribute that is not persisted in the database in any way.
Basic usage
Using an atkDummyAttribute is fairly easy. Just add it to a node and pass the desired text as the second parameter.
$this->add(new atkDummyAttribute("explanation", "Enter your mother's maiden name in the below field only if your mother agrees"));
Note that dummy attributes by default do not have a label (as its regular usecase normally doesn't require one). In the occasion that you do want the label to be visible, you can add the attribute flag AF_DUMMY_SHOW_LABEL.
A slightly more sophisticated version of the atkDummyAttribute is the atkParserAttribute. It has the same api, but features the substitution of template variables in the text.
Advanced usage
it is possible to use this attribute among other things to give a dynamic non edit field. a none dynamic string from other attributes should use atkParserAttribute instead.
for example:
$this->add(new atkAttribute("first_name", AF_HIDE_LIST|AF_FORCE_LOAD));
$this->add(new atkAttribute("last_name", AF_HIDE_LIST|AF_FORCE_LOAD));
$this->add(new atkDummyAttribute("name_citation"));
function name_citation_display($record)
{
if (strlen($record["last_name"]) <> 0)
{
$string = $record["last_name"] . ", ". $record["first_name"];
}
else
{
$string = $record["first_name"];
}
return $string;
}
Note the AF_FORCE_LOAD without it the fields wont be in the returned result if AF_HIDE_LIST is used
from a table of:
| John | Doe |
| Jane |
This should produce:
Doe, John
Jane
FAQ
Where are the attribute labels?
The atkDummyAttribute defaults to no label. If you wish to reinstate the label, configure it as follows:
public static function meta(atkMetaPolicy $policy) {
$policy->add("additional_price", "atkDummyAttribute", array(null, AF_DUMMY_SHOW_LABEL));
}
(Do not attempt to set the flag using the third argument to add(), and do not attempt to remove the label afterwards; it must be passed through to the atkDummyAttribute constructor, as above.)
See Also
- Usage without DB I/O Polymorphism - prevent an attribute from attempting to access the database; useful if you want to create a dummy "structured" attribute, such as a date attribute
- AtkExpressionAttribute - value is an SQL expression
- AtkParserAttribute - value is derived from other attributes