Chapter 5. Application base class

Table of Contents

An example application
Initialisation
application () constructor
run ()
.dbi.conf.php file
init() in derived class
Member variable debug - debug mode
Member array raw_views - Mark views as raw.
Registering and invoking page functions
defaultview ()
Calling functions in a subsession
Subsession arguments
Batched function calls
Destruction
Token management

Application class calls functions described by event objects.

An example application

applications must be derived from application.class and contain an init (), close () and defaultview () function.


<?
  error_reporting (-1);
  $debug = 0;

  require 'proc/application.class';

  # We must derive a new class from application.
  class MyApp extends application {

    # This is invoked once after the database connection in $this->db is
    # established and the token is validated if there is any.
    # You *MUST* register your views in here.
    function init ()
    {
      $this->add_method ('my_view', $this);

      # This is a good place for dbi.class definitions or to allocate
      # other objects like a <link linkend="sect-ui">user interface</link>..
    }

    function defaultview ()
    {
      $v =& new view ('my_view', array ('text' =&gt; 'Hello World!'));
      echo '<A HREF="' . $this->link ($v) . '">Click here.</A>';
    }

    function my_view ()
    {
      echo '<h3>' . $this->arg ('text') . '</h3>';
    }

    function close ()
    {
    }
  }

  $app = new MyApp;
  $app->debug = $debug;
  $app->run ();
?>