Invenzzia » Resources / Articles / A photo gallery tutorial / Introduction

1. Introduction

Doctrine

For many scripts and applications, ordinary communication with the database with the basic interface is not enough. The maintenance of the source code full of hand-written queries could be a painful experience, especially when the database structure is changing or we would like to add some new functionality to the existing version. A remedy for the increasing complexity are ORM systems (Object-Relational Mapping) that reflect the internal database structure in the application, using object-oriented interface and allowing simple and natural manipulations on the data. One of such libraries available for PHP5 is Doctrine, offering the programmer a wide variety of features. Here we are going to mention only a couple of them:

  1. The database structure defined in YAML files – they are legible and independent from the specific database engine and can be easily managed with a version control systems such as Subversion.

  2. The model generator – the classes corresponding to the database tables can be generated automatically from the descriptions in the YAML files.

  3. The database structure generator – moreover, Doctrine can export the entire structure to the database engine using the same files.

  4. A migration tool – simplifies the migration from the earlier version of the database without the risk of accidental data destruction.

  5. DQL: Doctrine Query Language – an extra layer over the SQL language integrated with the models.

  6. Built-in support for complex data structures, such as trees.

  7. Caching and transaction management tools.

Doctrine is built upon the standard database interface, PDO, available in PHP since 5.1 version. It has been expanded with extra functionality and supports a wide variety of database engines. In the MVC design pattern, Doctrine works in the model layer.

Open Power Template 2

In every advanced web application, the presentation layer plays an important role, displaying the data generated by the logic layer and the models. A common technique of building it are templates, simple files with HTML and pieces of extra code in any programming language that decide, where and how to show the particular data. Open Power Template 2 is a template engine providing a comprehensive support of the presentation layer. It consists of an objective programming interface and the parser of XML-based template language. Among various library features, we can mention:

  1. Validating the output document syntax on the server-side.

  2. Declarative template programming – you specify, what you want to have, not – how it is supposed to work and how to implement it.

  3. Lots of high-level language elements simplifying the most common tasks required from the presentation layer: multilingualism support, different types of lists or composing the output document from smaller templates.

  4. The presentation layer is independent from the PHP data types which allows to build portable templates and reuse the same code in different parts of the project or even different projects.

  5. True objective API based on the solutions that can be found in leading PHP frameworks.

To provide the optimal performance, the library compiles the templates to the simple PHP scripts, attempting to process as much as possible during the compilation. In the MVC design pattern, OPT works in the view layer.

How to read this article?

The goal of this article is to show the features offered by Doctrine and Open Power Template and the photo gallery is only a sample project used to achieve it. I am not going to provide detailed descriptions on generating thumbnails or validating the form data, although they are present in the source code. The less important issues are intentionally omitted in the article due to its size and the amount of other things that should be mentioned. The full source code can be found in the accompanying TAR.GZ archive. It has been documented and described, so I recommend to read it, too. The article mentions many different features of the libraries and in my opinion the best way is to split the reading into smaller parts, and the most of all – to experiment!

Although the source code of the photo gallery is available under the X11 license, you should not use it for production purposes.