Documentation
Model
- 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
- 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
- Dependencies injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Cache : So as not to redo the same calculations several times
-
Model :
How to use DAOs to access databases
- SQL : SQL requests on relational databases
- Redis : Requests on Redis databases
- Generic DAO : Simple DAO objects, to easily access a table
- Custom DAO : Custom objects, to encapsulate complex queries
- Plugins : How to create your own plugins, and a list of plugins offered by Temma
- Execution flow : How to manage the execution flow, between plugins and the controller
- Helpers : Items offered by Temma to help you in various circumstances
Presentation
The model layer is the one that manages the reading and recording of information in the database.
Temma offers 3 mechanisms for this:
- Direct access to the database, using the \Temma\Base\Database abstraction object.
- Automatic creation of a DAO object by the framework, to easily access a table without writing any code.
- Writing your own DAO objects, to make queries more efficient than an automatic tool would.
How to use these mechanisms is up to you. However, we suggest that you do this:
-
Start by using the DAO automatically generated by Temma. It allows you to write your application code quickly.
As long as you only need simple queries for a single table, this works fine. For example, you would write:
// retrieve a user from his username $user = $this->_dao->get($userId); // retrieve all users whose 'valid' field is true $validUsers = $this->_dao->search( $this->_dao->criteria()->is('valid') );
-
If you want to simplify the use of DAO, you can create your own DAO, which extends the default one.
For example, you can create a method:
which will be easier to use and much more explicit than:$proUsers = $this->_dao->getLastProfessionalUsers(5);
These additional methods will only be overlays serving to simplify the use of the DAO, but the implementation will always remain as simple and fast to write.$proUsers = $this>_dao->search( $this->_dao->criteria() ->equal('type', 'pro') ->is('valid'), ['date_creation' => 'desc'], null, 5 );
- Subsequently, you can enrich your personalized DAO, to make it perform complex queries (with joins on several tables, sub-queries, groupings, etc.). You will then have to access the database directly and write your own SQL queries, but you will benefit from the simplification mechanism for writing queries offered by the framework.
However, if you know SQL well, we encourage you to write your DAOs directly by placing SQL queries in them. It will always be more effective in the medium term.
Previous: | Cache |
Next: | SQL |
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
- 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
- Dependencies injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Cache : So as not to redo the same calculations several times
-
Model :
How to use DAOs to access databases
- SQL : SQL requests on relational databases
- Redis : Requests on Redis databases
- Generic DAO : Simple DAO objects, to easily access a table
- Custom DAO : Custom objects, to encapsulate complex queries
- Plugins : How to create your own plugins, and a list of plugins offered by Temma
- Execution flow : How to manage the execution flow, between plugins and the controller
- Helpers : Items offered by Temma to help you in various circumstances