ATK Demo Walkthrough – Lesson 6

From ATK Wiki

(Difference between revisions)
Jump to: navigation, search
(The Employees Node (Version 1))

Latest revision as of 17:40, 3 December 2008



In this lesson we introduce the atkMetaNode. So what is an atkMetanode? well it's a node that uses the meta data of the database to automaticly add the attribute for the fields it find. In layman's terms, a meta node allows a programmer to write all the code to add, edit, view and delete nodes from a table with a single line of code!

The Employees Node (Version 1)

To create a module like we did in lesson 1 for the employees, we now need just 1 line of code and that's the class definition. The atkMetanode will look for a table called the same as the classname and then it will build the node for you:

class lesson6_employee1 extends atkMetaNode {}

The Employees Node (Version 2)

Meta Nodes can be customized just like atkNodes, by adding attributes in the constructor. If the attribute was already discovered by the Meta Node, its definition is replaced by the one provided by the programmer in the constructor. Relations can also be added in the same way.

The Employees Node (Version 3)

Instead of adding code in the constructor as we did in Version 2, we can customize our Meta Node by writing a new function, meta(). In this function we set up a "policy" that modifies the way in which the Meta Node converts the database meta data into a Node.

The Employees Node (Version 4)

In this version we further customize the Employees Node, in the meta() function.

One of the customizations is the use of the hasOne() function. This is equivalent to adding an atkManyToOne relation in the node's constructor. There is also a hasMany() function, which is equivalent to adding an atkOneToManyRelation in the constructor.

The Departments Node

This node is functionally equivalent to the Departments node of Lessons 3 and 4, but has been re-written as a Meta Node.

The Module

The module file contains the menu entries for this lesson.

Personal tools