This post originated from an RSS feed registered with PHP Buzz
by Forum One.
Original Post: 8 tips for working with the API
Feed Title: Syntax Framework
Feed URL: http://blog.syntaxcms.org/rss.php?version=0.91
Feed Description: Finally, a place to answer Syntax questions
We've added a lot of very convenient methods to various SyntaxCMS classes to automate repetitive tasks and overall make common tasks easier. Here are 8 tips for using the API.
1) Get a URL to a Record's detail page.
Perfect for a module or template where you're working with muliple content types. It also makes it possible to rename a module without having to update templates.
3) Get all of a section's ancestors as a collection object
In some cases you might want to know all the ancestors for your section, maybe for building a breadcrumb.
$ancestor = $Section->getAncestorCollection()
4) Tell the general module to use a custom listitem template
The general module is very flexible in how it can retrieve lists of content. It has some built in automatic logic for determining what template to use to display a particular record in a list. You can override this behavior by passing the list capability a parameter named listitem.
This will have the general module look for a file named listitem-summary.tpl first in the template director of the module that handles a datatype. If that module does not exist or have that file, general will look for the template file in its own template directory.
5) obfuscate and email string
Useful to hide email from some spam harvesting bots.
6) Test if a record contains a field with a given name
In cases where you are working with collections of mixed content types, you may not know if a given record has a particular field. You can test for this with the following code:
if ($Record->has_field('upload'))
{
/ do something /
}
7) Test if a record is approved
Usually, a Collection object will only return approved records. If you need to test this at the record level, you can do:
if ( true == $Record->is_approved())
{
/ do something /
}
Test if the current user is authorized to see a record
Again, a Collection object will only return records that the current user can read. If you need to test this, use:
if ( true == $Record->is_authorized())
{
/ do something /
}