Site Administration Page 5 - Building a Barebones Content Management System: The Yaapi API |
After having shown you how to list the articles in a category, I will now demonstrate how to display the contents of an article in the list. You may have noticed that each article title in the previous example was linked to a script titled "article.php" (with the "id" of the article passed in the query string). It's time to review the PHP script. <?php // the include file // initialize objects // The $id variable should always have a value // The $id variable should always have a value ?> <HTML> // Get the intro for the article if(!isset($current_article) || !$current_article) { echo "<H2>$current_article->title</H2>"; ?> Click on the title of any article listed by "category.php" script to view the following output:
Now, let me guide you through the contents of my second PHP script. <?php // the include file // initialize objects // The $id variable should always have a value // snip You’ll notice that the first few lines are similar to those in "category.php": after including "article.class.php", I proceed to create an instance of the article() class for use in this script. Next, I assign value to the "$article_id" local variables. If I do not find a value in the query string, I assign the default value stored in the configuration file, as explained in the previous section. <% // snip <?php // Get the intro for the article if(!isset($current_article) || !$current_article) { echo "<H2>$current_article->title</H2>"; ?> // snip %> Now that I have an "id" for the article, I proceed to invoke get_article(). This aptly titled method returns the data associated with the article whose "id" is passed as the input to the method. I store the return value in another local variable, "$current_article" and use appropriate properties of the article() object to render the screen, as seen in the output. For your reference, I have listed the properties of the article() object below:
With this example behind me, I can safely conclude that I’ve now demonstrated two critical features that any practical CMS should provide: the ability to list the articles in the database, and then retrieve the actual content that constitutes an article.
blog comments powered by Disqus |
|
|
|
|
|
|
|