Documentation
Migration
Table of Contents ▼
Controllers: creation & naming
Controllers must inherit from the \Temma\Web\Controller object and not \Temma\Controller.
The names of controller objects no longer need to have the Controller suffix.
The names of action methods no longer need to have the exec prefix.
The controller initialization method must be called __wakeup() and not init().
The method for finalizing controllers must be called __sleep() and not finalize().
The root action must be called __invoke() and no longer index().
The proxy action must be called __proxy() and no longer proxy().
The name of the template file corresponding to the root action therefore becomes __invoke.tpl, and no longer index.tpl.
Controller utility methods now take an underscore at the beginning of their name, to avoid any ambiguity with the names of actions:
- $this->template() becomes $this->_template()
- $this->redirect() becomes $this->_redirect()
- $this->redirect301() becomes $this->_redirect301()
- $this->httpError() becomes $this->_httpError()
- $this->httpCode() becomes $this->_httpCode()
- $this->getHttpError() becomes $this->_getHttpError()
- $this->getHttpCode() becomes $this->_getHttpCode()
- $this->view() becomes $this->_view()
- $this->templatePrefix() becomes $this->_templatePrefix()
- $this->subProcess() becomes $this->_subProcess()
Views: naming
The names of the objects managing the views no longer have the "View" suffix.
- \Temma\Views\SmartyView becomes \Temma\Views\Smarty
- \Temma\Views\JsonView becomes \Temma\Views\Json
- \Temma\Views\CsvView becomes \Temma\Views\Csv
- \Temma\Views\RssView becomes \Temma\Views\Rss
- \Temma\Views\IniView becomes \Temma\Views\Ini
- \Temma\Views\ICalView becomes \Temma\Views\ICal
Plugins: creation
Plugins must inherit from the \Temma\Web\Plugin object and not \Temma\Controller.
Plugins may still have:
- Either a plugin() method, which will be systematically called when the object is used (as pre-plugin as well as post-plugin);
- or a preplugin() method and/or a postplugin() method, which will be called depending on whether the object is used as pre-plugin and/or post-plugin.
Note that the \Temma\Web\Plugin object inherits from \Temma\Web\Controller, so plugins are always controllers with additional capabilities. So a plugin can have actions in addition to its pre-/post-plugin methods.
Controllers & plugins: Template variables
To write or read in a template variable, we wrote:
$this->set('variable', $value);
$value = $this->get('variable');
Now you have to write:
$this['variable'] = $value;
$value = $this['variable'];
There are similar changes for sessions and cache management.
Controllers: Syntax sugar
Previously, when we wanted to make a redirection and then stop all processing (plugins and controller), we wrote:
$this->redirect($url);
return self::EXEC_HALT;
Now we can write:
return $this->_redirect($url);
Dependency injection component
An object centralizes the instances of the objects handled. It is accessible using the _loader attribute of the controllers.
For example, to access the object containing the configuration:
$this->_loader->config
You can make sure that your own objects are managed by the component (see the documentation).
This then allows you to use the objects without worrying about their instantiation.
For example:
$this->_loader->UserGateway->deleteUser($userId);
SQL: quote() and quoteNull()
If you write your SQL queries yourself, you escape the parameters with the quote() method. For example:
$sql = "SELECT *
FROM users
WHERE email = " . $db->quote($email) . "
LIMIT 1";
The quote() method always returns a string surrounded by apostrophes. So it will convert the string A student's paper to A student\s paper. And it will convert an empty string (as well as the null value) to ''.
Previously, the quote() method did not add apostrophes at the beginning and end of the processed string. It was therefore necessary to add them in the SQL query. It is not necessary any more.
The quoteNull() method does the same thing, except that if we give it an empty string (or null) as a parameter, it returns the NULL string (without apostrophes).
This can be useful when a field accepts null values, and we want to manage that.
In this example, the text field will be set to NULL if the $content variable is empty:
$sql = "INSERT INTO ARTICLE
SET title = " . $db->quote($title) . ",
text = " . $db->quoteNull($content);
SQL: Prepared requests
It is now possible to use prepared queries (see documentation).
Next: Installation
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
- 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