Callbacks

Callbacks are methods that you can create in the "includes/callbacks.php" file to perform various actions. They will be executed automatically either before the step is displayed, or after the user hits the "next" button. Each callback array items contains the following data:

  • name (required)
    The name of the callback method you would like to execute.
  • execute (optional, default: after)
    Allows you to specify when to execute the callback method. Available values are "before" and "after".
  • params (optional)
    Array of parameters you would like to submit to your callback method.

In the example below lets include the "is_installed" callback which will check if your applicaton is already installed.

<?php
$steps 
= array(
  array(
    
'name' => 'Welcome to the installation wizard',
    
'fields' => array(
      array(
        
'type' => 'info',
        
'value' => 'This wizard will guide you through the installation process.'
      
)
    ),
    
'callbacks' => array(
      array(
        
'name' => 'is_installed',
        
'execute' => 'before',
        
'params' => array('version' => '1.2')
      )
    )
  )
);
?>

We now need to include our "is_installed" callback method in the "includes/callbacks.php" file.

<?php
class Callbacks extends Callbacks_Core
{
  function 
is_installed($params = array())
  {
    
$current_version '1.0'// fetch the current script version from your app
    
if ( is_file(BASE_PATH '../system/config.php') ) {
      
$this->error 'System already appears to be installed.';
      return 
false;
    }
    elseif ( 
$params['version'] <= $current_version ) {
      
$this->error 'You are already running the latest version of the app.';
      return 
false;
    }
    return 
true;
  }
}
?>