PHP
  Home arrow PHP arrow Page 2 - Building Loader Apps in PHP
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  
PHP

Building Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2009-05-27


    Table of Contents:
  • Building Loader Apps in PHP
  • Start building loading programs with a require_once() function
  • Building a basic file loader class
  • The loader class in action

  • 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 Loader Apps in PHP - Start building loading programs with a require_once() function
    ( Page 2 of 4 )

    As I said at the beginning, the simplest version of a loading application can be built by explicitly calling some “include()/require()” functions, which are used per file requested. So, to recreate a typical scenario in which these functions are utilized, suppose for a moment that there are two basic files that need to be included within an application, that are defined as follows:

    ('sample_file1.php')

     

    <?php

    echo 'This file has been loaded with the require_once() function.' . '<br />';

    ?>

     

    ('sample_file2.php')

     

    <?php

    echo 'This file has been also loaded with the require_once() function.' . '<br />';

    ?>

    As shown previously, the two sample files listed above are extremely simple to grasp, so I’m not going to waste your time explaining how they work. Nonetheless, since there’s a fictional application that needs to include the files to do its business, a typical loader file would look like this:

    ('loader.php' file)

     

    // include first sample file via a require_once() function

    require_once('sample_file1.php');

     

    // include second sample file via a require_once() function

    require_once('sample_file2.php');

    Definitely, the definition of the “loader.php” file is very basic, but it does show in a nutshell a classic situation, where one “require()” function is called per requested file. In addition, the following output would be produced by the loader file:

    This file has been loaded with the require_once() function.

    This file has been also loaded with the require_once() function.

    This would be quite possibly the most basic implementation of a file loading mechanism in PHP. Despite its simplicity, it works pretty well when building small-scale applications.

    However, when it comes to developing larger PHP programs, things can get more complex. There will probably be multiple files using many includes. This situation can lead to dealing with tedious debugging and maintenance issues.

    So, to prevent the vast majority of these eventual problems, it’s necessary to create a file loading system that works in a more modular way, and at the same time allows us to abstract the whole loading process a bit further.

    This objective can be achieved quite decently by using a simple loader class. Therefore, in the course of the section to come I’m going to discuss how to build such a class in a few basic steps.

    To learn more about how this procedure will be accomplished, click on the link that appears below and keep reading.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





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