\myMVC_Controller

Main controller.

It manages all requests and responses. Example to use it:

define('SMARTY_DIR', '../Smarty/libs/'); require_once(SMARTY_DIR.'Smarty.class.php'); require_once('mymvc/myMVC.php'); require_once('../etc/etc.php'); // YOUR define file

$controller = new myMVC_Controller(); $controller->setRenderEngine(new myMVC_SmartyEngine($_SERVER['DOCUMENT_ROOT'].'/../pages/templates', $_SERVER['DOCUMENT_ROOT'].'/../pages/templates_c')); $controller->setActions(array('MainAction', 'TestAction', 'Test1Action', 'NoRightsAction', 'LoginAction', 'myMVC_BaseLogoutAction'), 'MainAction', 'NoRightsAction'); $controller->setViews(array('MainView', 'TestView', 'Test1View', 'NoRightsView', 'LoginView')); $controller->setLanguageInformation(array('de_DE' => 'Deutsch', 'en_US' => 'English', 'it_IT' => 'Italiano'), 'de_DE', $_SERVER['DOCUMENT_ROOT'].'/../locale', 'testmvc'); $controller->setFilter(myMVC_Controller::$FILTER_PREACTION, 'myMVC_LoginFilter', array(), array('loginAction' => 'LoginAction')); $controller->process();

Summary

Methods
Properties
Constants
__construct()
setRenderEngine()
getActionsList()
clearActionList()
getDefaultAction()
getCurrentAction()
getMenuActions()
hasUserRightForAction()
setActions()
setViews()
setFilter()
setLanguageInformation()
getAvailableLanguages()
getCurrentLanguage()
setCurrentLanguage()
process()
$FILTER_PREACTION
$FILTER_PREVIEW
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$request
$session
$defaultAction
$noRightAction
$actions
$views
$availableLanguages
$getTextLocaleDir
$getTextLocaleDomain
$languageParameter
$renderEngine
$filters
N/A

Properties

$FILTER_PREACTION

$FILTER_PREACTION : 

Type

$FILTER_PREVIEW

$FILTER_PREVIEW : 

Type

$request

$request : 

Type

$session

$session : 

Type

$defaultAction

$defaultAction : 

Type

$noRightAction

$noRightAction : 

Type

$actions

$actions : 

Type

$views

$views : 

Type

$availableLanguages

$availableLanguages : 

Type

$getTextLocaleDir

$getTextLocaleDir : 

Type

$getTextLocaleDomain

$getTextLocaleDomain : 

Type

$languageParameter

$languageParameter : 

Type

$renderEngine

$renderEngine : 

Type

$filters

$filters : 

Type

Methods

__construct()

__construct() 

Constructor.

Initializes all engines (Request, Session, Template engine, and so on)

setRenderEngine()

setRenderEngine(\class  $class) 

Set the render engine zu use for template.

Currently just myMVC_SmartyEngine is implemented.

Parameters

\class $class

The render engine. It must be a subclass of myMVC_BaseEngine

getActionsList()

getActionsList() : array

Returns a list of possible actions

Returns

array —

The list of the possible actions, or NULL if no action is registerd

clearActionList()

clearActionList() 

Deletes the currently saved action list.

It must be called after a successful login!

getDefaultAction()

getDefaultAction() : string

Returns the current defined default action.

Returns

string —

The class name of the default action or NULL if no default action was defined

getCurrentAction()

getCurrentAction() : string

Returns the current called action.

Returns

string —

The class name of the current action or NULL if no action was called

getMenuActions()

getMenuActions() : array

Returns the list of all actions, that should appear in the menu.

Returns

array —

The list of all menu action. It can be empty

hasUserRightForAction()

hasUserRightForAction(string  $action) : boolean

Returns whether the user has rights for the given action.

Parameters

string $action

The class name of the requested action

Returns

boolean —

true if the user has rights to call the action, false otherwise

setActions()

setActions(array  $actions, string  $defaultAction, string  $noRightAction = NULL) 

Set the available actions list.

Parameters

array $actions

Array of Action Class names (derived from myMVC_BaseAction)

string $defaultAction

Name of the default Action (called if no Action was given)

string $noRightAction

Name of the Action to be called if the current users does not have the rights for the called Action. If it is NULL, and the user doesn't have the rights, an Exception will be generated

Throws

\myMVC_MVCException

On problems

setViews()

setViews(array  $views) 

Set the available views list.

Parameters

array $views

Array of View Class names (derived from myMVC_BaseView)

Throws

\myMVC_MVCException

On problems

setFilter()

setFilter(integer  $type, string  $class, array  $exceptions = array(), array  $params = array()) 

Sets the filter for the controller.

A filter can be called before an action or a view IMPORTANT: just a filter per type can be defined!!

Parameters

integer $type

Filter type (myMVC_Controller::$FILTER_PREACTION or myMVC_Controller::$FILTER_PREVIEW)

string $class

The class of the filter (derived from myMVC_BaseFilter)

array $exceptions

Optional list of classes (Action or View, depending on filter type, which has to be excluded from filter [aka: the controller will call this class, and not the filter])

array $params

Optional parameters for the filter

Throws

\myMVC_MVCException

On problems

setLanguageInformation()

setLanguageInformation(array  $availableLanguages, string  $defaultLanguage, string  $getTextLocaleDir,   $getTextLocaleDomain, string  $languageParameter = 'lang') 

Set the language information (GetText)

Parameters

array $availableLanguages

Associative array of languages (code => description, eg. 'de_DE' => 'Deutsch')

string $defaultLanguage

Default language. It MUST be one in the array $availableLanguages

string $getTextLocaleDir

GetText Domain

$getTextLocaleDomain
string $languageParameter

Name of the parameter with the new language (default: lang)

Throws

\myMVC_MVCException

On problems

getAvailableLanguages()

getAvailableLanguages() : array

Returns all available languages in the program

Returns

array —

Associative array of languages (code => description, eg. 'de_DE' => 'Deutsch')

getCurrentLanguage()

getCurrentLanguage() : string

Returns the current used language

Returns

string —

The current language (eg: de_DE or en_US)

setCurrentLanguage()

setCurrentLanguage() 

Get the wanted language (from browser or from parameter) and load the language definition (for GetText)

Note: this function is PUBLIC, so that you can call it from CLI, too. To do that, use following code example:

$mainDir = dirname($_SERVER['SCRIPT_FILENAME']); if(substr($mainDir, 0, 1) != '/') $etcDir = $_SERVER['PWD'].'/'.$mainDir; else $etcDir = $mainDir; require_once('myMVC.php');

$controller = new myMVC_Controller(); $controller->setLanguageInformation(array('de_DE' => 'Deutsch', 'en_US' => 'English'), 'de_DE', $etcDir.'/../locale', 'myApplication'); $controller->setCurrentLanguage();

process()

process() 

Process the request.

Action or View will be evaluated.

Throws

\myMVC_MVCException

On problems