Temma offers optional PHP attributes to control access to controllers and actions.

These attributes can be added together, so you can add several different attributes (and sometimes the same attribute several times, with different parameters) to the same controller or action.

More, you can create your own attributes to manage access to controllers and actions.

Attributes provided by Temma

Temma provides several attributes, which documentation is available in the "Helpers" sections:

  • Auth: To restrict access to authenticated users.
  • View: To manage controller and action views.
  • Template: To define the path to the template file.
  • Method: To manage the authorized HTTP methods.
  • Referer: To filter access by HTTP REFERER.
  • Redirect: To redirect requests automatically

2Write your own attributes

You can create your own attributes to manage access to controllers and actions.


Your attributes must derive from the \Temma\Web\Attribute object, which offers several features relatively similar to those of controllers:

  • Access to template variables via the hooked notion.
    For example: $this['var'] = 'value'; to define a variable, and $var = $this['var']; to read the value of a variable.
  • Access to data sources in the form of direct object properties.
    For example: $this->db to access a database named db.
  • Methods $this->_httpCode() and $this->_httpError() to define the HTTP return code, or HTTP error code.
    Methods $this->_getHttpCode() and $this->_getHttpError() to retrieve the HTTP code previously defined.
  • Methods $this->_redirect() and $this->_redirect301() to define redirection commands.
  • Methods $this->_view() to define the view, $this->_template() to define the template, and $this->_templatePrefix() to define the template prefix.

2.2Execution flow

To modify the flow of execution, an attribute must raise a specific exception:

  • \Temma\Exceptions\FlowHalt: Stops the flow of execution. No other plugins or controllers will be executed, and the framework moves straight on to processing the view or redirection.
  • \Temma\Exceptions\FlowRestart: Restarts processing of the current phase (pre-plugins, controller or post-plugins).
  • \Temma\Exceptions\FlowReboot: Restarts the entire processing chain (pre-plugins + controller + post-plugins).
  • \Temma\ExceptionsFlowQuit: Stops execution of the framework. No further plugins or controllers will be executed. The view will not be executed and redirection requests are ignored.