• Your Cart is Empty
  • Cart
  • Log In

Symfony

What is Symfony?

Symfony is a PHP framework, which aims at accelerating the creation and maintenance of web applications and to replace recurrent coding tasks. There are a few prerequisites required for its installation: Linux, FreeBSD, Mac OS or Microsoft Windows, and a web server with PHP 5. The current version 1.2 supports only PHP 5.2 or higher, but the previous versions can be run on PHP 5.0 and 5.1 systems. Unfortunately, like many other new, modern frameworks, Symfony too lacks support for PHP4, but, on the other hand, it is compatible with almost every RDBMS (Relational Database Management System) and has low performance overheads.

Latest version: 1.2.4
PHP4
PHP5 PHP v.5.2.0 or later
MVC
Multiple DB
ORM
DB Objects
Templates
Caching
Validation
Ajax
Auth Module
Modules
Cost FREE

The Symfony framework overview

The Symfony PHP framework is easy to use thanks to its Ruby-On-Rails-like programming method, clean design and code readability. Symfony offers Ajax helpers, plugins and an admin generator interface, which renders the programming of complete applications truly easy. The developers can focus on applicative logic without wasting time to write infinite XML configuration files.

Symfony can be used for building robust applications in an enterprise context as it helps developers to test, debug and document projects, giving them full control over configuration and customization - from the directory structure to the foreign libraries.

Symfony uses the Model-View-Controller design pattern, which separates the business logic from the presentation layer.

Plus, if you choose Symfony you will benefit from the active, helpful open-source community that stands behind it.

Symfony - features summary

Symfony, which is designed to optimize the development of web applications, grows in features with every release. Aimed at shortening the development time of complex web applications, it automates common tasks so that developers can focus only on the specificities of an application.

Symfony - a database engine-independent PHP framework, which can be easily installed and configured, generates readable code with phpDocumentor comments. This MVC framework is easy to extend, features Propel plugins and allows integration with other vendor libraries. Developers can take advantage of the inbuilt internationalization layer allowing data and interface translation and content localization, and can reduce the amount of presentation code by encapsulating large shares of code in simple function calls. The presentation avails of templates and layouts that can be built by HTML designers who have no knowledge of the framework. The in-built form generator offers automated validation and repopulation of the forms. All Symfony-built applications support output escaping which protects them from attacks via corrupted data. The webmasters can benefit from the search-engine friendly routing, smart URLs, built-in e-mail and API management features, easily implementable Ajax interactions, and last, but definitely not least - one-line helpers that encapsulate cross-browser-compatible JavaScript effects.

Symfony provides various development environments and comes with several tools that help automate ordinary software engineering tasks:

  • code-generation tools for prototyping and one-click back-end administration
  • built-in unit and functional testing framework allowing test-driven development
  • a debug panel which speeds up debugging by displaying the info needed by the developer on the very page he is working on
  • a command-line interface, which automates the application deployment between two servers
  • logging features giving administrators complete information about an application's activities

Using Symfony - a quick tutorial with examples

As an example we will create a simple form that submits data to a database using the Symfony sandbox which has all the required libraries already included and the basic framework configuration is done.

The basic directory tree of the Symfony sandbox looks like this:

sf_sandbox/
_apps/
__frontend/
_cache/
_config/
_data/
_doc/
_lib/
_log/
_plugins/
_test/
_web/
__css/
__images/
__js/

And your domain is assumed to open the "web" directory. Now we need to describe the table that we will be using for our form. This is done by editing the file sf_sandbox/config/schema.yml. It is an XML like structured file and its contents should be as follows:

propel:
form_post:
id:           ~
title:        { type: varchar(255)}
data:      { type: varchar(255) }

In order to quickly create the classes for our model, we will use Symfony's Command Line Interface management tool located at sf_sandbox/symfony:

php symfony propel:build-model

This will create some models in sf_sandbox/lib/model/.

By default, Symfony is set to use a SQLite database file, and thus if we need to use MySQL, we should execute the following command:

php symfony configure:database "mysql:dbname=symfony_project;host=localhost" dbuser mypassword

Where dbname/dbuser/localhost/mypassword are respectively the database user, the database, the database host and the password to the dbuser.

Symfony also will create the database queries for the MySQL table creation and insert them using the following two commands:

php symfony propel:build-sql
php symfony propel:insert-sql

We also will need the form classes to be created with the following command:

php symfony propel:build-forms

For additional information on Symfony management tool options you can simply type "php symfony". Symfony can use the data model to create/retrieve/update/delete interface automatically:

php symfony propel:generate-module --non-verbose-templates --with-show frontend post FormPost

Here, frontend/post/FormPost is the application/module name and the model that will be used. The modules created are now located in:

sf_sandbox/apps/frontend/modules/

It is recommended to clear the cache after creating your module using the command

php symfony cache:clear

Now we have a fully operational form that can submit data to a database and also view/edit and delete it at: http://example.com/sf_sandbox/web/frontend_dev.php/post

For additional information, examples and API documentation you may want to check the Symfony official documentation page.

Resources: