AtkMetaNode: Difference between revisions
fix destruction |
No edit summary |
||
| Line 1: | Line 1: | ||
{{class|atk}} | |||
== Description == | == 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. | 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:35, 31 August 2008
|
Classname: atkMetaNode
|
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 metadata, 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
{
var $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");
}