Vesthelm Engine

2.1.4 User Guide

Action_Model Class

The Action_Model class provides functions to set controller actions and assign table columns names.

Creating Action_Model

Let's say you want to create bulletin board application. You might have action-model class that contains functions to set bulletin board application actions and table columns. Here is an example of what such action-model class might look like:

defined('V_IN_FRONTEND') or die('Powered by <a href="http://www.vesthelm.com/">Vesthelm EE</a>');

class Bulletin_Board_Bulletin_Action extends Vesthelm_Action_Model {

    public function __construct() {
        //$_POST actions
        $this->set('add', array('plan_id', 'category_id', 'period', 'user_id', 'username', 'payment_system'));
        $this->set('edit', array('id', 'plan_id', 'category_id', 'period', 'user_id', 'username', 'payment_system'));
        
        //$_GET actions
        $this->set('get', array('id'));        
        $this->set('get-images', array('id', 'field_name'));
    }

}

The first argument in the set() function is the name of the controller action. The second argument is array containing table column names.

Anatomy of Action_Model

Action_Model classes are stored in folders:

//Core action-models
example.com/frontend/models
example.com/acp/models

//Application action-models
example.com/applications/{application_name}/frontend/models
example.com/applications/{application_name}/acp/models

//Addon action-models
example.com/addons/{addon_name}/frontend/models
example.com/addons/{addon_name}/acp/models

//Sometimes action-models can be found here (old way):
example.com/addons/{addon_name}/frontend/classes
example.com/addons/{addon_name}/acp/classes

The basic prototype for action-model class is:

class Enhancement_Name_Action_Model_Name_Action extends Vesthelm_Action_Model {
    function __construct(){}
}

Where Enhancement_Name is the name of your enhancement. Enhancement names must have the first letter capitalized after underscore _ character.

Where Action_Model_Name is the name of your class. Class names must have the first letter capitalized after underscore _ character. Make sure your class extends the base Action_Model class.

The file name will be same as your class name (Action_Model_Name_Action). For example, if your class is:

class Bulletin_Board_Bulletin_Action extends Vesthelm_Action_Model {
    function __construct(){}
}

Your file will be:

example.com/applications/bulletin-board/acp/models/Bulletin_Action.php

//or
example.com/applications/bulletin-board/acp/models/bulletin/Bulletin_Action.php

Calling Action_Model

Calling Bulletin Board application action-model:

$Bulletin_Action_Model = $this->bulletin_board->Bulletin_Action;

//identical
$Bulletin_Action_Model->get();
$this->bulletin_board->Bulletin_Action->get();

Where bulletin_board is the name of enhancement and Bulletin_Action is the name of the Action_Model.