Ordering attributes within a node: Difference between revisions
if fields are added via a constructor, they will appear in the order in which they are added |
No edit summary |
||
| Line 3: | Line 3: | ||
==Ordering attributes within a node== | ==Ordering attributes within a node== | ||
If you have an <tt>atkNode</tt>, attributes (i.e. database columns) appear in the order in which they are added via <tt>atkNode::add()</tt>. | |||
If you have an <tt>atkMetaNode</tt> (or derived class), fields appear in the order in which they appear in the database. To control the order in which attributes appear within a node (i.e. on a "page"), use <tt>atkMetaPolicy::setOrder()</tt>, <tt>atkMetaPolicy::setIncludes()</tt> or the <tt>$order</tt> argument to either <tt>atkMetaNode::add()</tt> or <tt>atkMetaPolicy::add()</tt>. | |||
For example: | For example: | ||
| Line 19: | Line 21: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
( | (In the case of <tt>atkMetaNodes</tt>, the order in which attributes are added has no effect because they configure themselves [[Using the atkMetaNode|via database metadata]], and attributes are added to nodes before both the settings from <tt>atkMetaNode::meta()</tt> are applied, and the <tt>atkMetaNode::postMeta()</tt> method is run--"adding" an attribute via either of these methods <em>reconfigures</em> an existing attribute. Attributes <em>will</em> appear in the order in which they are added in a constructor, but this is discouraged.) | ||
Revision as of 11:58, 14 July 2008
|
ATK Howto: Ordering attributes within a node
|
Ordering attributes within a node
If you have an atkNode, attributes (i.e. database columns) appear in the order in which they are added via atkNode::add().
If you have an atkMetaNode (or derived class), fields appear in the order in which they appear in the database. To control the order in which attributes appear within a node (i.e. on a "page"), use atkMetaPolicy::setOrder(), atkMetaPolicy::setIncludes() or the $order argument to either atkMetaNode::add() or atkMetaPolicy::add().
For example:
public static function meta(atkMetaPolicy $policy) {
$policy->add("invoice_start_date", "atkDateAttribute");
$policy->add("invoice_end_date", "atkDateAttribute");
$policy->setOrder(array(
"invoice_start_date",
"invoice_end_date"
));
}
(In the case of atkMetaNodes, the order in which attributes are added has no effect because they configure themselves via database metadata, and attributes are added to nodes before both the settings from atkMetaNode::meta() are applied, and the atkMetaNode::postMeta() method is run--"adding" an attribute via either of these methods reconfigures an existing attribute. Attributes will appear in the order in which they are added in a constructor, but this is discouraged.)