AtkDummyAttribute

From Achievo/ATK Wiki

Jump to: navigation, search

Attribute: atkDummyAttribute

API docs | Flags

List of other attributes

atkDummyAttribute screenshot

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.

Contents

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

If the contents of the dummy attribute depends on the currently edited record, and the atkParserAttribute isn't flexible enough, then you can use an atkDummyAttribute in combination with a display override to add arbitrary content to a screen.

In the below example, we use this principle to hide both the 'first_name' and 'last_name' columnts, and instead show a dummy attribute that provides a concatenated version of the full name.

  $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 flag; without it the fields won't be in the SQL query for this screen. Since we need them anyway in the display override, we apply AF_FORCE_LOAD to make sure the values are always loaded even if they are hidden.

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

Personal tools
Navigation