Login   Register  
PHP Classes
elePHPant
Icontem

File: 02_directory_listing_sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of J.B.  >  Simple Object  >  02_directory_listing_sample.php  >  Download  
File: 02_directory_listing_sample.php
Role: Example script
Content type: text/plain
Description: Sample use of class DirectoryListing
Class: Simple Object
Base class with common variable access functions
Author: By
Last change:
Date: 2004-04-21 15:14
Size: 1,415 bytes
 

Contents

Class file image Download
<?php
    
#    This script shows how use of SimpleObject and its child classes
    #    may ease your programming
    
    #    TASK - List all directory files
    
    #    include all required classes
    
require_once('simpleobject.php');
    require_once(
'simpleiterator.php');
    require_once(
'DirectoryIterator.php');
    require_once(
'simpletemplate.php');
    require_once(
'listtemplate.php');
    
    
#    Create an instance of list template:
    #    Send an instance of DirectoryIterator as argument
    
$list_tpl =& new ListTemplate(new DirectoryIterator('/path/to/dir'));
    
    
#    Set title (variable in template) to list
    
$list_tpl->set('list_title','What a Simple file listing!');
    
    
#    Display the list of items:
    
$list_tpl->display('list_template.html','item_template.html');
    
    
#    That's it!
    
    #    Don't forget to make list_template.html and item_template.html
    #    files such that they have markers like <!--$field_name--> in
    #    item_template.html and <!--$list--> and <!--$list_title-->
    #    in list_template.html. <!--$list--> will be replaced by output
    #    of item listing:
    
    /*
        list_template.html:
        
        <h1><!--$list_title--></h1>
        <p>Here are the files of /path/to/dir directory:</p>
        <table>
        <tr>
            <th>filename</th>
        </tr>
        <!--$list-->
        </table>
        
        
        item_template.html:
        
        <tr>
            <td><!--$name--></td>
        </tr>
        
        You can modify DirectoryIterator to make it
        match your requirements
    */
?>