The Artima Developer Community
Sponsored Link

PHP Buzz Forum
8 tips for working with the API

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Forum One

Posts: 118
Nickname: forumone
Registered: Sep, 2004

Forum One is consulting firm specializing in helping non-profits improve their online presence.
8 tips for working with the API Posted: Jun 15, 2006 11:26 PM
Reply to this message Reply

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
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Forum One
Latest Posts From Syntax Framework

Advertisement

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.

<a href="<?= f1cms::getDetailUrl($Record) ?>"><?= $Record->getName() ?></a>

2) Get a section's absolute URL on the site

Sections, which are essentialy a site's pages, also have a method to return a public URL.

<a href="<?= $Section->getNavPath() ?>"><?= $Section->getName() ?></a>

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.

echo f1cms::callModule('general', 'list', array('listitem' => 'summary'))

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.

echo StxUtilities::obfuscate_asci('omerida@example.com');

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 /
}

8) 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 /
}

Read: 8 tips for working with the API

Topic: Serendipity 1.0 Previous Topic   Next Topic Topic: No More Loners!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use