ATK FAQ
General Questions
Where can I go if this FAQ doesn't answer my question?
The Forum is helpful to get answers to any questions you might have that are not covered here. Also have a look at the many howto's that are available for ATK.
atkMetaNode Questions
Special attribute flags don't seem to work in the meta method
This is one of the biggest gotchas about the meta functionality, special attribute flags like AF_BOOL_* or AF_MANYTOONE_* are defined in the attribute/relation, but, unless you explicitly include the attribute/relation in question by putting 'useattrib('atkboolattribute');' or 'atkrelation('atkmanytoonerelation');' at the top of the file you can't use the flags (the autoload can't include for missing constants).
So if you want to use such Attribute Flags, use:
useattrib("atkboolattribute");
What is the difference between meta() and postMeta() ?
Broadly speaking, the 'meta' method is 'pre-compile' (where the meta stuff compiles to an atkNode) and the postMeta is 'post-compile'. Because we want to be able to cache as much as possible it's a good idea to configure your node as much as possible in the meta method.
Use of the constructor in atkMetaNodes is discouraged, why?
Use of the constructor in atkMetaNodes is discouraged because you should be able to most things in the meta static method and everything else in the postMeta. Using the constructor is reserved for normal nodes and will lead to confusion with developers that have to maintain/extend your functionality.
How can I improve performance of an atkMetaNode?
Remember to define the meta method as a static, to enable caching!
Record list Questions
I want an extra action added to the icons that appear in a recordlist
This howto: Custom Record Actions covers how to create custom actions, and also how to add them as an icon to a recordlist. Even if you want to add an icon that calls an already existing action, this howto contains useful bits on how to do that.
Attribute Questions
Setting the value of ATK attributes
One gotcha that a lot of new developers run into is that ATK has it's own internal representation of data from attributes and relations. You usually come across it when trying to manually add values to a node with the addDb/updateDb or setting data in a record in the preAdd/preUpdate triggers. For instance, where you get a plain string in the YYYY-MM-DD string format from the database for a date field, ATK will convert this (with the db2value method) to an array with the 'year','month' and 'day' values. So if you try this: $record['mydate'] = '2008-09-19'; ATK won't store it. You have to use the internal format.
To convert a string value to the internal representation as used by the attribute, use:
$attr = $this->getAttribute("mydate");
$record["mydate"] = $attr->parseStringValue("2008-09-19");
How can I implement my own validation logic on a field?
See this howto: Custom Validation Logic
How can I validate a file before upload?
The atkFileAttribute has a validate method that you can override, as documented in the Custom Validation Logic documentation. However, when it's validating, you don't have the actual file yet (it will only really save the file after everything is valid).
So, if you want to check the file itself during validation, you can get $record["picture"]["tmpfile"] and process that, e.g.:
function picture_validate(&$record, $mode)
{
// find out the size of the file they want to upload.
$size = getimagesize($record['picture']['tmpfile']);
$width = $size[0];
$height = $size[1];
if ($width > 400 || $height > 400)
{
triggerError($record, "picture", "You can upload only pictures smaller than 400 pixels in height and width");
}
}
Development Questions
How can I turn on debugging dynamically?
See the Turning on debugging at runtime howto.
Can I write the debug output to a file?
If you set '$config_debuglog' to a www-user-writable file, your application will write all debugging that is registered to be shown to this file. This is very useful for situation where the debugging is registered but never shown (because of a recursive error causing Apache to segfault). Please note that it's not a good idea to turn this on in staging applications as you may not be the only one making requests on the application with debugging on. And remember to turn this off! Because you can imagine that this file may grow quite a bit over time :)