This article will show you how to use the different API methods of yaapi, which is an API tool useful for managing content. It will explain how to retrieve a list of articles, display an article on a web page, retrieve a list of categories, and more.
As I may or may not have already mentioned, yaapi is an object-oriented API. It consists of a utility article() class that is equipped with a bunch of useful properties and utility methods -- youíve already seen its constructor in action in the first part -- that strikes the right balance. While it is not so complicated that it intimidates a novice PHP programmer, it does provide enough functionality that it will not disappoint the experts.
Consider this: the article() class has a get_recent() method, which returns the last five items added to the database. I can conveniently invoke this method to render a "Whatís New" section on my website without the need to resort to any custom programming.
The bottom line: the object-oriented approach of yaapi allows me to update the business logic encapsulated within its API methods. For example, if I want to update the aforementioned get_recent() method to return ten items instead of five, the default value, all I need to do is tweak the core PHP script containing the definition of the articles() class, and the front-end display is updated seamlessly.
Coming back to the introductory section (of this article): I spoke about "articles" and "categories", the two entities at the core of the yaapi application. Let me provide some insight about them and why they play such a critical role as far as my barebones CMS is concerned.
An "article", as the name suggests, is the most basic unit in yaapi (and most CMS software packages). Each article in yaapi is associated with a bunch of attributes; these include among other things the "title", "author" (or "authoress") and his/her "email address", the "category" (more about this in a minute) and finally, we have the "content" that represents an article. I can also turn off the display of an article without having to delete it from the database, courtesy of an "approved" attribute.
Next, I demystify the concept of a "category." In a yaapi context, this concept allows me to group "articles" logically. Letís consider the example of the website on which you are reading this article -- DevShed. Youíll notice that the content has been organized on the basis of different technologies. So, you have categories such as "PHP" for PHP-related articles, "Perl" for Perl-related articles, "Apache" for Ö you get the picture!
Yawning already, are you? Well, things begin to get interesting from here on as I demonstrate how different methods of the yaapi article() class can be used in PHP scripts. I promise.