PHP Classes

File: index.php

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


Class file image Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <title>Actions dispatcher example</title>



include "";
// Actions dispatcher helps you to write clean PHP code, allowing an environment on wich all PHP script calls are made trough the same script (normally index.php). Actions dispatcher takes the petition from index.php and performs any operation related to that petition, according to the previously defined actions.
    // So, this is and index.php example file. In this, we build our Actions dispatcher object
    // The parameters for the constructor are: <main file (normally index.php)>, <default action if no other is provided>
$actions = new actions_dispatcher ("index.php", "default_action");

// Now, imagine that your code is placed in an external class, open (attached file) and take a look at its source code comments.
    // We include our example class with our functionalities for the application we're building using Actions dispatcher:
include "";
// Build our example_class object:
$example_class = new example_class ();
// And add the actions that are related to all the funcionalities performed on
$example_class->addactions ();
// Also, we add the action corresponding to the default action, wich will be called when no action information is passed to index.php
$actions->addaction ("default_action", &$example_class, "default_action", "");
$actions->doaction ();
// You probably are thinking all this stuff is unnecessary, and it's a very fast way to complicate even more all your code, but you'll find it's very useful if you are habituated to work with lots of classes. You'll also find that is a perfect way to keep your code clean, because every block of code is just in the place it has to be, and not fragmentated in a big index.php.
    // It's just another view of PHP scripting, forget all those linear-executing scripts, and put some *action* in you code ;)
    // Improvements, comments or suggestions are welcomed at