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

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

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

Parameters

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

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

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

Example

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