Administration
  Home arrow Administration arrow Page 6 - Building a Barebones Content Management System: The Yaapi API
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ADMINISTRATION

Building a Barebones Content Management System: The Yaapi API
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2005-09-21


    Table of Contents:
  • Building a Barebones Content Management System: The Yaapi API
  • Under The Hood
  • yaapi -- Getting Started
  • yaapi -- Listing Articles
  • yaapi -- Display An Article
  • yaapi - Display List Of Categories

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Barebones Content Management System: The Yaapi API - yaapi - Display List Of Categories
    ( Page 6 of 6 )

    One final bit before I drawn the curtains on this part of the series: I would like to update my application to display a list of categories in the left hand side menu, which was thus far populated with a bunch of static links. This is what I want it to look like:

    Fortunately, yaapi comes to my rescue once again. This time it is the turn of the get_categories() method of the article() class that comes in handy. Since I need to display this menu on every page, it is only logical that I encapsulate the code that lists the categories in a separate function that can be invoked along the lines of my custom number_of_elements() function, listed earlier.

    This is what my custom function, titled render_lhs_menu() and defined in the "inc.config.php" file, looks like:

    <?php

    // snip

    // function to display the left hand side menu
    function render_lhs_menu($article) {

     $return_value = "";
     $categories = $article->get_categories();

     for ($count = 0; $count < count($categories); $count++) {

      $return_value .= "<P><A HREF=\"category.php?id=".$categories[$count]['id']."\" >".$categories[$count]['name']."</A></P>";
     }

     return $return_value;
    }

    // snip

    ?>

    There is no rocket science here. The function accepts an instance of the yaapi article() object as an input parameter and retrieves all the categories by calling the get_categories() method. As you may have guessed, this function returns an associative array containing the id and name of each category in the database. It concatenates the required HTML output as it iterates over the array and returns a string value to the calling script (say "article.php"), which in turn echoes it to the browser, as you can seen below.

    <%

    // snip

    <TR HEIGHT="350">
     <TD WIDTH="25%" ALIGN="MIDDLE" VALIGN="TOP">
       <?php echo render_lhs_menu($article);?>
     </TD>
     <TD>
     
       // snip

     </TD>
    </TR>

    // snip

    %>

    Finally, I have managed to make all components of my web page dynamic -- yes, I have excluded the footer section as it remains constant across most websites. You may argue that I could have defined another function to return the content for this footer section. Good point; I leave that as an exercise for you.

    Conclusion

    This brings me to the conclusion of the second part of the "Building a Barebones Content Management System" tutorial.

    Let me quickly recap the topics that I covered today. Initially, I gave a detailed introduction to the different entities that drive yaapi. Next, I demonstrated how to retrieve a list of articles in a particular category as well as display the content of a selected article using the get_categories() and get_article() methods respectively. After that, I developed a custom function that returns the HTML code required to display the categories defined in yaapi. Finally, I have an application that fetches data from the database and renders it in a logical manner, as one expects from any program worthy of being called a CMS application.

    In the next part, I shall introduce the patTemplate template engine. After demonstrating a few examples that show the versatility of this software API, I will integrate it with the PHP scripts listed today, thereby bringing me closer to fulfilling my goal of developing my barebones CMS.

    Till then, enjoy!



     
     
    >>> More Administration Articles          >>> More By Harish Kamath
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek