PHP Classes

File: example_class.inc.php

Recommend this page to a friend!
  Classes of Outdated profile   actions_dispatcher   example_class.inc.php   Download  
File: example_class.inc.php
Role: Example script
Content type: text/plain
Description: Example class well commented
Class: actions_dispatcher
A better, clean way to PHP scripting.
Author: By
Last change:
Date: 21 years ago
Size: 1,455 bytes
 

Contents

Class file image Download
<?

   
class example_class
   
{
       
// A function inside every of our classes to add the actions it performs
       
function addactions ()
        {
            global
$actions;
           
// Here we add two actions, one for executing the function inside this class, called "something1", and the other for "something2".
            // The parameters for addaction are: <name for the action>, <a reference to the object wich will perform the action>, <function name inside the object>, <array of parameters to pass to the function, in the form of array ("param1", "param2", "param3" ...)
           
$actions->addaction ("something_to_do_1", &$this, "something1", "");
           
$actions->addaction ("something_to_do_2", &$this, "something2", "");
        }
       
        function
something1 ()
        {
           
// This is a very simple function, but it shows a link with a call to the Actions dispatcher (note the variable "a").
            // When we click on this link, index.php will be called, the Actions dispatcher will catch the petition (trough the "a" variable) and perform the assigned task to "something_to_do_2"
           
echo "Something to do 1, click <a href=\"index.php?a=something_to_do_2\">here</a> to perform the action 'something_to_do_2'<br>";
        }
       
        function
something2 ()
        {
            echo
"Something to do 2.<br>";
        }
       
        function
default_action ()
        {
            echo
"The default action has been called, you haven't passed the action parameter (a), or there aren't any action refering to it.<br>";
        }
    }

?>