Jump to content

Ordering attributes within a node

From NusaATK
Revision as of 11:58, 14 July 2008 by Mjs (talk | contribs)

ATK Howto: Ordering attributes within a node

Complexity: Basic
Author: Ivo Jansch <ivo@achievo.org>

List of other Howto's

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.)