MySQL
  Home arrow MySQL arrow Page 8 - Data Management Made Easy Using Nenniu...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
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? 
MYSQL

Data Management Made Easy Using Nennius: Advanced Data Handling
By: Brian Vaughn
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2005-08-03

    Table of Contents:
  • Data Management Made Easy Using Nennius: Advanced Data Handling
  • Advanced Application Configuration
  • Expanding Our Application Menu
  • Creating the User Comments Component
  • Creating Component Dependencies
  • Component Notes
  • Help Files
  • File Attachments

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Data Management Made Easy Using Nennius: Advanced Data Handling - File Attachments


    (Page 8 of 8 )

    Now that our Comments component is finished, let's re-visit our News component. Begin by opening the news component's descriptor file, '/descriptors/news.php'. Once again our file contains only the required information, but by making a few simple modifications our component can gain a great deal of added functionality.

    For instance: what if we wanted to add functionality for admin users to attach images to news releases, so that the our front-end system can display a photo gallery? What if we wanted the system to keep records of when each release was posted and modified, and by whom? We could do that very simply by adding a few lines to the end of our existing defaults file:

    # set file attachment associations for component

    # NOTE: these fields allows for zero to an infinite number of file attachments

    #       to be associated with component via a seperate indexing table.

    $GLOBALS['g_optional_attachments_db_table']   = 'news_attachments';

    $GLOBALS['g_optional_attachments_db_key']     = 'id';

    $GLOBALS['g_optional_attachments_db_index']   = 'news_id';

    $GLOBALS['g_optional_attachments_db_filename']       = 'filename';

    # set record history table info (to record record creation & modification)

    $GLOBALS['g_optional_history_db_table']              = 'news_history';

    $GLOBALS['g_optional_history_db_key']         = 'id';

    $GLOBALS['g_optional_history_db_index']              = 'news_id';

    $GLOBALS['g_optional_history_db_user_id']     = 'user_id';

    $GLOBALS['g_optional_history_db_datetime']    = 'datetime';

    $GLOBALS['g_optional_history_db_description'] = 'description';

    Using Hook Functions

    At this point our example 'news' application is complete, but our learning exercise is not. We still have not discussed another powerful feature available to Nennius developers: hook functions.

    Nennius supports a fairly robust set of p-defined hook functions, allowing developers to enhance or override default behavior without modifying the Nennius engine directly. A hook function isn't needed for this example application, but we'll create one anyway in order to familiarize ourselves with how to do so. Our hook function will simply prevent the modification or deletion of any news article older than one week.

    Please begin by opening the '/components/news.php' file and adding the following information:

    #-----------------------------------------------------------------

    # returns TRUE / FALSE, indicating if record is locked for edit / delete

    #-----------------------------------------------------------------

    function is_edit_lock() {

            $f_component_details   = NULL;

           

            # retrieve necessary API objects from control class

            $db_api =& $this->nennius_control->get_db_api();

           

            # retrieve component's primary key

            $f_component_details   = $this->nennius_control->get_component_details();

            $news_id               = $f_component_details['id'];

           

            # run query to determine the date of record creation

            $db_query = "  SELECT  datetime

                           FROM    `news`

                           WHERE   id = $news_id

                             AND   datetime < NOW() - 5184000";

            $db_api->query( $db_query );

           

            # if a result has been found, then record is too old to edit

            if ( $db_api->get_num_rows() > 0 )

                   return TRUE;

           

            # if no result has been found, record is editable

            else    return FALSE;

    } # END is_edit_lock()

    As you can see, the above function retrieves the current component's details from the Nennius Control class, runs a SQL query to determine if the record in question is older than one week, and then returns TRUE or FALSE, indicating whether the record is locked for deletion. This is a rather simple example, but it suggests the power available to Nennius developers through the use of hook functions.

    Conclusion

    Although this article has taken a brief look at several of the advanced features available to Nennius developers, it is in no way a comprehensive list. The main purpose of the example application we have constructed was to demonstrate a variety of common ways Nennius may be configured to handle data. You are encouraged to take the finished product, and modify it to gain a better understanding of the configuration options we have discussed. You may also want to refer to the Nennius developer manual (http://nennius.sourceforge.net/dev_manual.php) for a more detailed list of hook functions and configuration options.

    A completed version of the application we have just created is available online (http://nennius.sourceforge.net/nennius/webapps/news_mod/). You may also download the source code for the application (http://nennius.sourceforge.net/nennius/webapps/news_mod.zip). If you have any questions or would like to learn more about the Nennius application engine, please visit the Nennius website (http://nennius.sourceforge.net/) or check out the Nennius forums (http://nennius.sourceforge.net/phpbb/).


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This is the third and final article in this series, and I thank all of you who have...
     

       

    MYSQL ARTICLES

    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT