waViewActions

Conitainer class for multiple PHP actions

Contents...

Parent class: waController.

See explanation of HTTP request routing in backend and in frontend.

Usually PHP actions for processing HTTP requests and returning HTML string back to browser are organized in the form of separate PHP classes extending waViewAction. But, if actions are very simple, they can be grouped in one class extending waViewActions.

Each action in such a conitainer class must be represented by a public method named by rule [action_id]Action; e.g.:

<?php

class myappBackendActions extends waViewActions
{
    public function defaultAction()
    {
        //...
    }

    public function pageAction()
    {
        //...
    }

    public function settingsAction()
    {
        //...
    }
    
    //...
}

Controller files & classes

Files and classes of controller containers must be named by rules similar to those applying to waViewAction, with the exception that 'action' part must be replaced with 'actions'.

HTML template files for grouped actions must be named and placed exactly as described for waViewAction class.

Methods

  • execute

    Executes an action with specified ID described in the same PHP class.

  • getTemplate

    Returns path to HTML template file currently used by an action.

  • getTheme

    Returns instance of waTheme class containing information about frontend design theme.

  • postExecute

    Executes additional code upon execution of any action described in the same class.

  • preExecute

    Executes additional code before execution of any action described in the same class.

  • setLayout

    Sets current layout (waLayout).

  • setTemplate

    Sets path to alternative HTML template file.

  • setThemeTemplate

    Sets HTML template file for a frontend action.

public function execute ($action, $params = null)

Executes an action with specified ID described in the same PHP class.

Parameters

  • $action

    Action ID.

  • $params

    Optional array of parameters, which can be passed to class method corresponding to specified action ID.

Example

$this->execute('page', array(
    'id' => $page_id,
));

protected function getTemplate ()

Returns path to HTML template file currently used by an action.

Example

$current_template = $this->getTemplate();

public function getTheme ()

Returns instance of waTheme class containing information about frontend design theme.

Example

$theme = $this->getTheme();

public function postExecute ()

Executes additional code upon execution of any action described in the same class. This method must be implemented by the developer, if necessary

protected function preExecute ()

Executes additional code before execution of any action described in the same class. This method must be implemented by the developer, if necessary

This method is convenient for setting a layout to be used by actions, described in this class, for generating web page HTML code.

Example

<?php

class myappBackendActions extends waViewActions
{
    public function preExecute()
    {
        $this->setLayout(new myappBackendLayout());
    }

    public function defaultAction()
    {
        //...
    }

    public function pageAction()
    {
        //...
    }
    
    //...
}

public function setLayout (waLayout $layout = null)

Sets current layout (waLayout).

it is convenient to call this method within method preExecute for setting current layout for pages generated by actions described in this class.

Parameters

  • $layout

    Instance of class waLayout, which must be used for defining the general layout of pages generated by actions.

Example

$this->setLayout(new myappBackendLayout());

public function setTemplate ($template)

Sets path to alternative HTML template file. When this method is called, an action can have no HTML template file as described above.

Parameters

  • $template

    Path to template file, which can be specified in the following ways:

    • absolute path to file,
    • name of HTML file without extension; this case assumes that a name of an existing HTML template file of the same app or plugin is specified, which must match the naming rules described above.

Examples

//for an app
$this->setTemplate('BackendOrder');
$this->setTemplate(wa()->getAppPath('templates/actions/backend/BackendOrder', 'someapp'));
//for a plugin
$this->setTemplate('BackendOrder');
$this->setTemplate(wa()->getAppPath('plugins/myplugin/templates/actions/backend/BackendOrder', 'someapp'));

protected function setThemeTemplate ($template)

Sets HTML template file for a frontend action class.

Parameters

  • $template

    Name of a design theme HTML template file.

Example

$this->setThemeTemplate('page.html');