Documenation

The Model

The Model is the core of the framework. Without it none of Swiftlet functions will work.

The Model can be accessed through the $model object, an instance of the model class (/_model/model.class.php) which should be available throughout the entire code. Most global functions and values are stored here (e.g. $model->siteName).

Class

$model

Public functions

  • $model->hook ( string $hook )
    Use to create a hook.
  • $model->hook_register ( string $plugin, array $hooks )
    Used in plug-ins to register hooks.
  • $model->check_dependencies ( array $dependencies )
    Use to make sure a required plugin is installed and ready (e.g. $model->check_dependencies(array('db')) if database access is needed). If not, an error message is displayed.
  • $model->h ( string $v )
    Shorthand for htmlentities($v, ENT_QUOTES, 'UTF-8'), used to make values safe for HTML.
  • $model->t ( string $v )
    Translates a string. Requires a Language plugin.
  • $model->format_date ( string $date [ , string $type ] )
    Formats a date and time. $type can be date, time or datetime (default). Also see Time.
  • $model->email ( string $to, string $subject, string $body [ , array $headers ] )
    Send an e-mail. Requires an E-mail plugin.
  • $model->route ( string $route )
    Create a route ("pretty URL") to a page or file. This works best with URL rewrites enabled in /_config.php and on the server.
  • $model->confirm ( string $notice )
    Displays a confirmation page. This can be used to get confirmation from the user when making permanent changes like deleting a page. See Forms.
  • $model->error ( string $errNo, string $errStr [, string $errFile ] [, string $errLine ] [, array $errCont ] )
    Use to display an error message and stop the script.

Public variables

  • $model->userIp
    The user's internet IP address (this can be IPv4 or IPv6).
  • $model->authToken
    Authenticity token used with forms (see Forms).
  • $model->contr
    Instance of the contr class (same as $contr). See Controllers.
  • $model->view
    Instance of the view class (same as $view). See Views.
  • $model->configMissing
    This variable is set to TRUE if the configuration file is missing.
  • $model->debugOutput
    Debug notices generated throughout the code. The contents are shown when an error occurs (and in the generated source code) if debugMode is set to TRUE in /_config.php. The notices can be used to track down bugs.

Every value of the configuration file is also available as a variable, e.g. $model->debugMode.

Constants

  • model::version
    Model version number.