MySQL
  Home arrow MySQL arrow Page 4 - 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 
Mobile Linux 
App Generation ROI 
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 - Creating the User Comments Component


    (Page 4 of 8 )

    Now that we have finished configuring the application, let's create our basic Comments component. Just like last time, we'll start by creating the entry-point file. Name that file 'comments.php' and place it within the '/nennius/webapps/news/' directory. Then copy the following content into it:

    <?php

    # define location of component & descriptor files

    $component_file        = 'components/comments.php';

    $descriptor_file       = 'descriptors/comments.php';

    # include parent nennius_component class

    include_once "../../nennius.component.php";

    include_once $component_file;

    # create a new object to kick things off

    new comments( $descriptor_file );

    ?>

    Next let's move on to the Comments descriptor file ('/descriptor/comments.php'):

    <?php

    # set   display name for component

    $GLOBALS['g_main_display_name']               = 'User Comments';

    # set primary db table name

    $GLOBALS['g_db_primary_table']        = 'comments';

    # set primary key for main db table

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

    # set (optional) primary display field for db table

    $GLOBALS['g_db_primary_table_name']   = 'subject';

    # set required min. threshold for overall access

    $GLOBALS['g_threshold_overall']               = $GLOBALS['USER'];

    ?>

    So far things should look pretty familiar, which is good. At their most basic level, all Nennius components will look very similar. The components file ('/components/comments.php') is no exception. Let's create it next:

    <?php

    # basic comments component

    class comments extends nennius_component {

            # store class-wide reference to control object

            # NOTE: this object is created by the nennius_component class

            var $nennius_control                          = NULL;

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

            # sets up necessary internal vars, creates new control object

            # and passes self-reference to it

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

            function comments(     $p_component_descriptor_file   ) {

                  

                   # call out to constructor of parent class with descriptor file

                   $this->nennius_component(      $p_component_descriptor_file );

                  

            } # END comments

           

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

            # retrieves and returns assoc. array containing db column info

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

            function get_info_db_array() {

                   $f_db_info_array       = NULL;

           

                   # define primary key attribute for comments table

                   $f_db_info_array['id'] = (

                           array (

                                   'db_field_name'        => 'id',

                                   'db_field_type'        => 'int',

                                   'db_field_length'      => 3,

                                   'db_primary_key'       => TRUE,

                                  

                                   # field is hidden from visibility at all times

                                   'hidden_all'           => TRUE

                           )

                   );

                  

                   # news id - links comment entries to parent news release entry

                   $f_db_info_array['news_id'] = (

                           array (

                                   'db_field_name'        => 'news_id',

                                   'db_field_display'     => 'News Release',

                                   'db_field_type'        => 'int',

                                   'db_field_length'      => 36,

                                   'db_field_required'    => TRUE,

                                   # foreign key DB information

                                   'db_foreign_key'       => 'id',

                                   'db_foreign_display'   => 'title',

                                   'db_foreign_table'     => 'news'

                           )

                   );

                  

                   # date & time when comment was posted

                   $f_db_info_array['datetime'] = (

                           array (

                                   'db_field_name'        => 'datetime',

                                   'db_field_display'     => 'Date / Time',

                                   'db_field_type'        => 'datetime',

                                   'db_field_length'      => 19,

                                   'db_field_required'    => TRUE,

                                  

                                   # set default value to be current date & time

                                   'update_default'       => date( 'Y-m-d H:i:s' ),

                                  

                                   # set attribute to be searchable by min & max date range

                                   'search_date_range'    => TRUE

                           )

                   );

                  

                   # commentor's name

                   $f_db_info_array['name'] = (

                           array (

                                   'db_field_name'        => 'name',

                                   'db_field_display'     => 'Name',

                                   'db_field_type'        => 'char',

                                   'db_field_length'      => 50,

                                  

                                   # set field to be searchable using a partial-match criteria

                                   'input_search_type'    => 'TEXT',

                                   'search_partial'       => TRUE,

                           )

                   );

                  

                   # comment's subject

                   $f_db_info_array['subject'] = (

                           array (

                                   'db_field_name'        => 'subject',

                                   'db_field_display'     => 'Subject',

                                   'db_field_type'        => 'char',

                                   'db_field_length'      => 100,

                                  

                                   # set field to be searchable using a partial-match criteria

                                   'input_search_type'    => 'TEXT',

                                   'search_partial'       => TRUE,

                           )

                   );

                  

                   # comment body / text

                   $f_db_info_array['comment'] = (

                           array (

                                   'db_field_name'        => 'comment',

                                   'db_field_display'     => 'Comment',

                                   'db_field_type'        => 'char',

                                  

                                   # define size of textarea input

                                   'input_update_type'    => 'TEXTAREA',

                                   'input_update_rows'    => 10,

                                   # hide field from search & view modes

                                   'hidden_search'        => TRUE,

                                   'hidden_view'          => TRUE

                           )

                   );

                  

                   # after all attributes have been setup, return array

                   return $f_db_info_array;

                  

            } # END get_info_db_array()

           

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

            # retrieves and returns assoc. array containing display headers

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

            function get_info_header_array() {   

                   $f_header_info_array   = NULL;

                          

                   # append default header messages

                   $f_header_info_array['news_id'] = 'News Information';

                   $f_header_info_array['name']   = 'User Information';

                   $f_header_info_array['subject']       = 'Comment';

                  

                   # return header array

                   return $f_header_info_array;

                  

            } # END get_info_header_array()

    } # END comments class

    ?>

    Things should still look somewhat familiar. As you can see we've simply described the SQL table that stores our User Comments information, and set some basic configuration options about each of the component's attributes (aka SQL columns). However, a very important attribute was introduced with the 'news_id' column: the foreign key.

    As previously stated, most data management systems will not only need to manage various data components but also control those components in relation to one another. Nennius allows for several methods of interaction between components, one of which is the foreign key attribute we have just identified. By specifying a foreign table, key, and display column we are providing Nennius with all of the information it needs to transparently link the Comments component to the News component. The result of this (in this example) is a drop-down menu containing all News entries, listed by title, that a user may pick from when creating or modifying a Comment record. This creates an association between Comments and News records.

    We also introduced a new function in this component file: 'get_info_header_array()'. This function defines headers that are displayed above certain attributes when a record is being created or modified. This is a very useful tool when creating components with a high number of attributes. By using the 'get_info_header_array()' function a developer is easily able to categorize and organize the various form elements - making the resulting update form more user-friendly.

    More MySQL Articles
    More By Brian Vaughn


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

       

    MYSQL ARTICLES

    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - 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





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