Blog

Release: New Verb Data API for PHP February 18, 2010

It's been a while since we've had a major feature announcement here at Verb CMS, but this is a big one! We're proud to announce Version 2 of the Verb Data API, which is available and running on all Verb accounts as of today.  The new API is an object-oriented replacement for the current verb() and verb_find() functions in PHP, and is also used by any VerbML tag that accepts a path="" attribute.

The biggest feature of the new release is performance.  The old Verb Data API has long been a major bottleneck for Verb sites, especially on sites with large amounts of data or heavy use of associations.  With the new release, we have addressed both of these issues head-on, and have reduced page rendering times by as much as 90% for some pages.  The upgrade is included in all Verb plans for no additional charge.

Behind the scenes, the new API is powered by a new set of Verb Database servers running our new proprietary database server software, VerbDB.  VerbDB is a ground-up rewrite of Verb's data storage and query engine.  All data  (including associations) is now stored in RAM at all times to enable lightning-fast lookups without having to read from the disk. Additionally, VerbDB analyzes your query history to anticipate future queries and get your data ready before you even ask for it.

The other major feature of the new API is its object-oriented nature.  Since examples are worth 1000 words, here's a quick overview of how the new API works.  Non-coders might want to skip this part.

verb() and verb_find() are now the same function and may be used interchangeably.

They return a VerbContext or VerbQuery object that contains the results of your query.  VerbContext and VerbQuery present mostly the same interface.  Let's start up the example with a familiar looking query that retrieves an Artist by ID:

$artist = verb("artists/13421");

Child structures may be accessed by either the arrow operator or via array notation:

echo $artist->name;
echo $artist['name'];

If your query returned multiple contexts (for example if you asked for a collection), you may iterate over the object just like it was an array:

$artists = verb("artists");
foreach ($artists as $artist) {
  echo $artist->name;
}

You can get the ID, permalink, or type of any context easily, via the arrow operator or array notation:

$artist = verb("artists/13421");
echo $artist->id;           // 13421
echo $artist->permalink;    // artist/freefall
echo $artist->type;         // Collection
echo $artist->name->type;   // TextItem
echo $artist->albums->type; // Collection

You can also get info about the structure represented by the context:

$artist = verb("artists/13421");
echo $artist->structure->id;        // 1269
echo $artist->structure->name;      // Artists
echo $artist->structure->type;      // Collection
echo $artist->structure->permalink; // artist   (URL of page to render by default for permalinks)

You can still get the ID in the foreach block too:

$artists = verb("artists");
foreach ($artists as $id => $artist) {
  echo $artist->name;
}

Run scoped XPath queries via the get() method, which supports any valid Verb XPath expression:

$artists = verb("artists");
foreach ($artists as $artist) {
  foreach ($artist->get("albums[type='CD']") as $album) {
    echo $album->name . " is a CD!";
  }
}

All query options that were previously supported are still supported.  We have also added query options for pagination. They get passed in as a parameter, after the query. Supported options include filter, groups, limit, order, paginate, page, and skip:

$artists = verb("artists", array('limit' => 10));
$artists = verb("artists", array('paginate' => 5, 'page' => 2));
$albums = $artists->get("albums", array('order' => 'name'));
$albums = $artists->albums(array('order' => 'name')); // same as above, shortcut syntax

Debugging functions like var_dump() (including serialize(), print_r(), var_export(), etc.) will not work directly on the new objects. However, we've wired up a special method that will allow you to debug your code like many of you have always done.  Just invoke the debug method on the object:

var_dump($artist->debug);

Note:  Internally the debug() method is the same as the data() method, which I'll tell you about in a second.

And for the really geeky, a few more implementation details: The $context variable passed into functions registered with verb_register_hook() will now be a VerbContext object. You may manipulate it in your hook functions just as if you had created it in PHP.  Additionally, you can create a VerbContext object out of your own vanilla PHP arrays by invoking the verb_context() function on that array.

You don't have to do anything at all to enjoy the speed boosts and object-oriented features provided by the new API. 

We've rolled it out onto your sites and you are up and rolling.  You may begin using the Object-Oriented features in your PHP code right away as well.  Over the next few months, we will use statistics gathered from the system to build in further optimizations for speed.

*** IMPORTANT ***

For the most part, this API is backwards-compatible with the old API. There is, however, a few things about the new API that may break your old code, though we checked and don't think they affect any websites currently live.

You may no longer directly iterate over the child structures of a context.  For example, this used to work, but will not work anymore:

foreach (verb("artists") as $artist) {
  foreach ($artist as $structure_name => $value) {
    echo $structure_name . ": " . $value . "\n";
  }
}

This change was necessary in order to combine the verb() and verb_find() functions into a single function.

This would work though:

foreach (verb("artists") as $artist) {
  echo "name:  " . $artist->name  . "\n";
  echo "genre: " . $artist->genre . "\n";
  echo "bio:   " . $artist->bio   . "\n";
}

That is, you want your code to explicitly state the name of the structure you wish to access.

If you need to access context data as an array (like before), just invoke the data() method on the object:

foreach (verb("artists") as $artist) {
  foreach ($artist->data as $structure_name => $value) {
    echo $structure_name . ": " . $value . "\n";
  }
}

Also, you need to be careful using objects in "if" statements, as the object will always return true.  For example, this will not work as expected:

if (verb("artists")) {
  echo "There are artists";
}

You can use the ->count() method to achieve what you want:

if (verb("artists")->count) {
  echo "There are artists";
}

Additionally, you should be careful when casting values to a numeric type.  This will not work as expected:

foreach (verb("artists") as $artist) {
  echo (int)$artist->age;
}

This is because objects may not be directly cast to numeric types.  If you need a numeric value, you'll need to first cast to a string.

foreach (verb("artists") as $artist) {
  echo strftime("%m-%d-%Y", (string)$artist->formed_on);
}

I think that covers most of the breaking changes and gotchas.

Thanks for reading this far.  I hope that this made your day.  I also hope that I explained everything fully and that there are no unforeseen complications or bugs.  If you have any questions or notice any issues, please email support@actionverb.com and we'll get it  ironed out immediately.

I really appreciate your support of Verb CMS, and look forward to bringing you many new toys in the future!

Kevin Bombino
Founder
Verb CMS

Release: Production Environments! December 23, 2009

Hey guys!  It's been a while, but the time has come for a new Verb feature.  And we think this one is huge.  We're proud to announce that Verb now has full support for a separation of Staging and Production environments on your website.

We worked hard to develop this feature in a way that fits in naturally with the different workflows employed by the many different designers using Verb.  Basically, this is how it will work:

Once you opt-in to Verb's Production Environment feature for one of your domains by going to the Domains tab under the Verb tab, Verb will create a Production Environment for that website.  FTP will be directed to the Staging Environment, which can be browsed at http://<;site>.verbsite.com/.  Any changes made to the FTP will be instantly reflected there.  However, they will not be reflected on the main domain until perform a 'release'. 

You can release your site to the production environment from the new Production Environment tab under the Verb tab.

5 previous releases are stored, and you may roll back to them at any time.  This provides an awesome recovery option if you accidentally release a bad copy of the site.

Here's what it looks like:

Screenshot of Releases

You may also make a new release by using the Verb Local Development Environment.  Simply type verb release to make a new release to production.  Or type verb stagerelease to update the Staging Environment and Production Environment with the current copy from Subversion.

The best part of all: there is no additional cost for this feature.  It's just one more thing that we're doing to make Verb the most powerful and unique shared hosting environment in existence.  Thanks for your support!

If you have any questions, please direct them to support@actionverb.com.

Video Tuesday: Building Zips July 28, 2009

Get the Flash Player so you can see an awesome video about Verb.

Today we're showing you how to dynamically create zip files using Verb's <v:zip> tag. For more videos and examples, check out our Documentation and Integration Center.

Video Tuesday: Permalinks July 14, 2009

Get the Flash Player so you can see an awesome video about Verb.

Permalinks keep your address bar clean, is good for SEO, and is easy to implement with Verb. As always, check out our Documentation and Integration Center for more videos and tutorials.

Using <v:rss> With Google Product Search July 08, 2009

As you may know, <v:rss> makes it easy to quickly create an RSS feed from any Collection in your site. Verb also takes this a step further by making it easy to create an RSS feed that can be submitted to Google Product Search, so potential customers can locate your items when querying this search engine. In this mini tutorial, we'll create an RSS feed that's ready to submit to Google Product Search.

Here's our example Collection that we're going to be working with; it's called "Records":
Structure

<v:rss> works with any Collection, so you can quickly create RSS feeds from your existing Collections.

Next, we'll need to write the code inside our rss.xml file. Normally it takes just one line of VerbML code to create an RSS feed; since we're submitting this feed to Google Product Search, we'll have to add some Google Base tags. Here's the contents of our rss.xml file:

<v:rss title="Action Verb Records" description="Records" path="records" title_field="record_name" description_field="description">
<g:condition>new</g:condition>
<g:id><v-></g:id>
<g:payment_accepted>Visa</g:payment_accepted>
<g:payment_accepted>MasterCard</g:payment_accepted>
<g:payment_accepted>AmericanExpress</g:payment_accepted>
<g:payment_accepted>Discover</g:payment_accepted>
<g:price><v=price></g:price>
</v:rss>

And we're all done! When we load up the RSS file in our browser, we can see the contents of the Collection is now accessible via RSS:
Output

If our customers wanted to easily stay up-to-date on what records we have for sale, they could subscribe to this RSS feed using any browser or RSS client. Since we can use <v:rss> to output the contents of any Collection, we could just as easily create an RSS file for our blog or any other Collection our customers might want to subscribe to.

Since we integrated the Google Base Tags into our RSS feed, it's ready to be submitted to Google Product Search [just follow Google's instructions]. After we submit it, our records will appear in Google Product Search results, and we'll have increased traffic to our website without much effort.

Video Tuesday: <v:formmail> July 07, 2009

Get the Flash Player so you can see an awesome video about Verb.

Verb's <v:formmail> helps you quickly make a form that submits to an email address.

Want more videos and tutorials? Check out our Documentation and Integration Center.

New Feature: Fulfillment Methods Added July 06, 2009

We've added new fulfillment methods to make Verb's eCommerce even better. Our Australian customers will be happy to know that they can now utilize Australia Post eParcel. For those of us in the states, you can now use USPS fulfillment with Endicia; this means you can print up postage right from your office!

To start using these new fulfillment methods, clicking on the 'Settings' subtab of your 'Store' tab:
Fulfillment Screen

Click on any of the Fulfillment Methods to add them:
Australia
(Australia eParcel)

Endicia
(USPS w/ Endicia)

New Feature: Quickly Add New Child Collection Entries July 01, 2009

 When two Collections are linked by an Association Structure [single], it sometimes can be a pain to add a new entry to the Child Collection, when creating a new entry in the Parent Collection. Verb loves making your clients' lives easier, so we've added a new feature to make alleviate this issue. The Association Structure [single] create screen now contains a checkbox called Display "Create New" option. When enabled, it gives users the option of adding a new entry to an associated Child Collection, when modifying its Parent Collection. Confused? Let's try an example.

Here we are creating an Association Structure between two Collections called 'Shows' and 'Venues':
Create Association

Notice the enabled Display "Create New" option. Now, when we add a new 'Show' to the 'Shows' Collection (aka the Parent Collection), we can select "Create New Venue" from the Venue select menu. We're then presented with an inline form where we can create a new Venue, without having to navigate to the Venue Collection:
Shows Create

Great. Now the next time a band on Action Verb Records goes on tour, we can easily add new Venues as we add new Shows.

Posts by Category:
Go to page: