AtkMetaNode: Difference between revisions
| Line 35: | Line 35: | ||
A comprehensive tutorial on the atkMetaNode can be found in [[Using_the_atkMetaNode|the atkMetaNode Howto]] | A comprehensive tutorial on the atkMetaNode can be found in [[Using_the_atkMetaNode|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: | |||
<syntaxhighlight lang="php"> | |||
class project extends atkMetaNode | |||
{ | |||
protected $flags = array(NF_READONLY); | |||
} | |||
</syntaxhighlight> | |||
The following properties are available: | |||
;$flags:To set the [[Node Flags]]. | |||
;$table:To set the name of the table to use for its data | |||
==Frequently Answered Questions== | ==Frequently Answered Questions== | ||
Revision as of 15:13, 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
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:
- $flags
- To set the Node Flags.
- $table
- To set the name of the table to use for its data
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");
}