Jump to content

AtkMetaNode: Difference between revisions

From NusaATK
No edit summary
Line 1: Line 1:
== Description ==
== Description ==


The atkMetaNode is a derivative of atkNode. It's main feature is the fact that it derives most of its functionality from the database metadata.
The atkMetaNode is a derivative of atkNode. Its main feature is the fact that it derives most of its functionality from the database metadata.


If this is a regular node:
If this is a regular node:

Revision as of 07:49, 25 June 2006

Description

The atkMetaNode is a derivative of atkNode. Its main feature is the fact that it derives most of its functionality from the database metadata.

If this is a regular node:

 useattrib("atktextattribute");
 
 class project extends atkNode
 {
   function project()
   {
     $this->atkNode("project"); 
     $this->add(new atkAttribute("id", AF_AUTOKEY));
     $this->add(new atkAttribute("name"));
     $this->add(new atkTextAttribute("description"));
 
     $this->setTable("project");
   }
 }

Then this would get you exactly the same result:

 class project extends atkMetaNode {}

In this example, atkMetaNode would find a table called 'project', look in the database matadata, find out that there's an id and name field, and do the rest automatically.

atkMetaNode tutorial

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

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
 {
   $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 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");
 }