Jump to content

ATK FAQ: Difference between revisions

From NusaATK
New page: = General Questions = == Where can I go if this FAQ doesn't answer my question? == The [http://forum.achievo.org/forum Forum] is helpful to get answers to any questions you might have th...
 
Line 37: Line 37:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
   $attr = $this->getAttribute("mydate");
   $attr = $this->getAttribute("mydate");
   $record["mydate"] = $attr->parseString("2008-09-19");
   $record["mydate"] = $attr->parseStringValue("2008-09-19");
</syntaxhighlight>
</syntaxhighlight>



Revision as of 12:47, 18 August 2008

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!

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");

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 :)