AtkMetaNode

From Achievo/ATK Wiki

Jump to: navigation, search

Classname: atkMetaNode

API docs

List of other documented ATK classes

Contents

Description

The atkMetaNode is the single most important class in every ATK application. It is the baseclass for all your business entities. It is called 'meta' because it uses the metadata from the database to implement functionality.

Under the hood, atkMetaNode is a derivative of atkNode, which is a more basic implementation that doesn't have as much 'magic' and is typically only used when we don't want any meta magic to happen.

A typical implementation of an atkMetaNode is:

  class project extends atkMetaNode 
  {
  }

In this example, atkMetaNode would find a table called 'project', look in the database metadata, find out that there's an id and name field, and do the rest automatically. This one line class is all you need to create a CRUD application based on the project table. Of course, you'll want to customize behaviour, but we'll show you how to do that in the rest of this document.

atkMetaNode tutorial

A comprehensive tutorial on the atkMetaNode can be found in the atkMetaNode Howto

Properties

The atkMetaNode supports several properties that can be set to influence behaviour.

An example of this is the property $flags that can be used to define the default flags:

  class project extends atkMetaNode
  {
    protected $flags = array(NF_READONLY);
  }

The following properties are available:

table  
table name
sequence  
sequence name
db/database  
database name or instance
policy  
meta policy, the meta policy to use ((sub-)class atkMetaPolicy instance)
grammar  
meta compiler, the meta compiler to use ((sub-)class atkMetaCompiler instance)
handler  
meta handler, handler which needs to be called instead of the default meta method
flags  
The Node Flags
descriptor  
descriptor template for this node
order  
(default) order to sort fields
index  
create indexed navigation on a attribute/fieldname
filter  
filter
securityAlias  
security alias for this node
securityMap  
security map for this node (will be added to the existing security map!)
compiler  
meta compiler, the meta compiler to use ((sub-)class atkMetaCompiler instance)
cacheable  
control whatever this meta node is cacheable (by default a metanode is cachable if the meta method is defined static or if there is no meta method defined)
type  
alternative name for the node type

Frequently Answered Questions

Why do I get "Fatal error: Can not extend non-existing class 'atkMetaNode' in ..."?

The atkMetaNode is not included by default (to save resources for scripts not using it). In the class where you need it, you can add the following line:

  atkimport("atk.atkmetanode");

If you use it heavily, and don't mind that it's always included, you can put this line in your atk.inc file instead.

My table is "tbl_project" but my node should be called "project". Can I still use the atkMetaNode?

Yes:

  class project extends atkMetaNode
  {
    protected $table = "tbl_project";
  }

How can I set flags on an attribute?

  class project extends atkMetaNode
  {
    function meta(&$policy)
    {
      $policy->setFlags("name", "description", AF_SEARCHABLE);
    }
  }

How can I set flags on the node itself?

  class project extends atkMetaNode
  {
    var $flags = NF_LOCK;
  }

This only works for a single flag because PHP won't accept the '|' symbol in a variable declaration. If you need multiple flags, use:

  class project extends atkMetaNode
  {
    var $flags = array(NF_LOCK, NF_EDITAFTERADD);
  }

How can I change the type of attribute that the metanote has decided to use?

  function meta(&$policy)
  {
    $policy->setType("description", "atkFckAttribute");
  }

How can I use tabs in the atkMetaNode?

  function meta(&$policy)
  {
    $policy->setTab("description", "advanced");
  }
Personal tools
Navigation