Documentation
Redirect attribute
Table of Contents ▼
Presentation
This attribute can be used to force a redirection, systematically preventing access to a controller or action. This can be useful during debugging, or to temporarily disable access to a portion of code.
Parameters
The attribute offers several parameters:
- $url: (string) Redirection URL.
- $var: (string) Name of the template variable containing the redirect URL.
Priority
To define the URL to which the user will be redirected, the attribute applies the following order of priority:
- If the $url parameter is defined, it is used.
- If the $var parameter is defined, and it contains the name of an existing, non-empty template variable, its content is used.
- If the temma.json file contains an x-security extended configuration, and this contains a redirect key, its content is used.
If no redirect URL is found, a 403 error is returned.
Configuration
To ensure that all Redirect attributes redirect to the same URL, simply define it in the temma.json file:
{
"x-security": {
"redirect": "/temporaryHomepage"
}
}
To ensure that the redirect URL is the same for the Auth, Method, Referer and Redirect attributes, simply define the redirect key in the x-security extended configuration in the temma.json file:
{
"x-security": {
"redirect": "/login"
}
}
Examples
use \Temma\Attributes\Redirect as TµRedirect;
// redirects all accesses to this controller
// to the URL defined in the temma.json file
#[TµRedirect]
class Login extends \Temma\Web\Controller {
// ...
}
use \Temma\Attributes\Redirect as TµRedirect;
class Homepage extends \Temma\Web\Controller {
// redirects to new home page
#[TµRedirect('/newHomepage')]
public function oldHome() { }
}
use \Temma\Attributes\Redirect as TµRedirect;
class Homepage extends \Temma\Web\Controller {
// controller initialization: definition of
// the 'homeRedir' template variable
public function __wakeup() {
$this['homeRedir'] = '/otherHomepage';
}
// redirection to the URL defined in the
// 'homeRedir' template variable
#[TµRedirect(var: 'homeRedir')]
public function action1() {
// ...
}
}
Previous: | Referer attribute helper |
Next: | urlize Smarty helper |
Table of Contents
- Migration : How to upgrade from Temma 1.x to version 2
- Installation : Download Temma and install it to start your web project
- Configuration : All the configuration directives of the etc/temma.json file and the optional environment variables
- External libraries : How to use external function libraries
- Routing : Temma's default routing system, and advanced routing
- Log : Use of the log system, management by criticality levels
- Controllers : Essential parts of your web application
- Views : Smarty templates or JSON/CSV/RSS/iCal/INI exports
- Dependency injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Data sources : Unified data access management
- Model : How to use DAOs to access databases
- Execution flow : How to manage the execution flow, between plugins and the controller
- Plugins : How to use plugins, and create your own plugins to modularize your code
- Attributes : How to filter access to controllers and actions
- Tests : To write automated integration tests.
- Command-line interface : To create executable scripts on the command line, automatically initialized by Temma
-
Helpers :
Items offered by Temma to help you in various circumstances
- Command-line scripts
-
Controller + plugin
- Auth : Controller and plugin to manage user authentication
- Plugins
- Attributes
-
Smarty plugins
- urlize : Modifier to transform a text into an URL
- filenamize : Modifier to transform a text into a file name
- nbsp : Modifier to transform spaces into non-breakable spaces
-
Utility objects
- ANSI : To format texts written to standard output
- BaseConvert : To do digital base conversions
- DataFilter : To filter and validate data
- Email : To send emails
- HTMLCleaner : To clean up an HTML stream coming from a WYSIWYG editor
- IniExport : To export data in INI format
- Json : To read JSON streams that may contain comments
- Lock : To lock access to a file, or the execution of the current PHP script
- Registry : To properly store global variables
- Smarty : To process Smarty templates outside the view
- Term : Terminal management (TTY)
- Text : Different treatments on character strings
- Timer : To manage stopwatches