Jump to content

Ordering attributes within a node: Difference between revisions

From NusaATK
Despam
Mjs (talk | contribs)
changed explanation, added reference to setOrder()
Line 3: Line 3:
==Ordering attributes within a node==
==Ordering attributes within a node==


By default, the order in which attributes appear in a node is based on the order in which they are added to it. You can influence this however by passing a positive integer as third parameter to atkNode's add() method.  
By default, 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:


If you don't pass this parameter, ATK will use increments of 100, starting with 100 for the first atttribute. So if you add an attribute later on, and want it to appear between the first and second attribute, pass 150 as third parameter, like this:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$this->add(new atkAttribute("value"), NULL, 150);
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"
  ));
}
</syntaxhighlight>
</syntaxhighlight>
(The order in which fields are added has no effect because fields 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" a field via either of these fields reconfigures an existing node.)

Revision as of 11:05, 14 July 2008

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

By default, 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"
  ));
}

(The order in which fields are added has no effect because fields are added to nodes before both the settings from atkMetaNode::meta() are applied, and the atkMetaNode::postMeta() method is run--"adding" a field via either of these fields reconfigures an existing node.)