Symfony offers extensive features such as excellent debugging and logging, but the learning curve is steeper than most Credit: Andis Rea | shutterstock.com Symfony, sponsored by Sensio Labs, is a well-known PHP framework that integrates a number of open source PHP projects. (For example, Symfony uses the Zend framework’s logging system.) Conversely, some Symfony components are available as stand-alone libraries from the Symfony components website. The current version (1.4.8, at the time of this writing) is written in PHP 5, and requires PHP 5.2.4 or later. Symfony demands a bit more of a learning curve than the other Web frameworks. If you’re new to Symfony, working through the Getting Started tutorial is highly recommended. Fortunately, the Symfony website provides a prebuilt, easy-to-understand application called the “Symfony sandbox.” Just download it, unzip it in your Web root, and it’s ready to run. The application is preconfigured to use the SQLite database engine (though you can configure the application for a different database engine) and provides a fine way to explore a Symfony application without having to construct one yourself. Symfony’s command-line tool (called, fortunately, “Symfony”) will generate application components and jump-start development for the whole application itself. For example, to create the default directory structure and base files for an application project named Album_Project, you enter: php symfony generate:project Album_Project Symfony environments and toolsSymfony recognizes four different “environments” in which an application executes — development, test, staging, and production — and makes it easy to accommodate each one (you need merely change a setting in the front-end index.php file). Different features are enabled or disabled depending on the environment you’ve set. For example, if an exception occurs in the development environment, Symfony will display extensive stack trace information on the Web page — which would never be permitted in the production environment. Test Center Scorecard 40%25%25%10% Symfony 1.4.89799 8.5 Very Good Symfony’s view system is architected on the decorator design pattern, in which you specify the fundamentals of a view by defining a template (really just a PHP file) that determines the appearance and behavior of a single page and embedding the template in a layout, which carries global view information to be applied to all pages. Symfony provides plenty of elaborations on this theme. You can define reusable chunks of template code called “partials.” You can also create “slots,” which are placeholders that can be inserted in just about any view element and whose components are filled in the same way you would assign a value to a variable. Symfony makes extensive use of the YAML (Yet Another Markup Language) template language. YAML defines your database model’s schema, specifies the settings for your application’s views, and configures environments, session settings, security, and other characteristics of the controller layer. In short, when you dive into Symfony, be prepared to learn YAML. Symfony’s debugging features are outstanding. Turn debugging on, and a debug toolbar appears in the upper-right corner of every page of your application. (Examine the Web page’s source and you’ll see piles of JavaScript and HTML that Symfony generated to assist with debugging.) Buttons on the toolbar reveal dropdowns from which you can view information such as the headers of the most recent HTTP exchanges between the browser and server, settings for Symfony global variables, PHP configuration information, parameters passed to the current view template, and more. Symfony also does quite a bit of logging, which you can examine from the debug toolbar. I was able to follow the steps that a request passes through to produce a response, beginning with the routing that occurs when a request arrives at the application index.php file all the way to the formulation of the HTTP response. In addition, when you run Symfony in a development environment, it will log all SQL queries into a log subdirectory. Because Symfony code does not expose SQL directly, this logging feature is useful if you need to track down database-related problems that are not apparent at the object level. (This SQL logging information is also available from the debug toolbar.) Symfony database ins and outsSymfony uses an ORM (object relational mapping) system for database access. Actually, Symfony uses either of two popular PHP ORM frameworks: Propel and Doctrine. Consequently, low-level SQL is abstracted away from the development process, and you can treat all database access as being the manipulation of persistent objects. It’s not a cakewalk, though. To actually create classes and methods for accessing your database tables, you must take one of two routes. If you’re comfortable with SQL, you can build the database and tables, then use a command like the following to create the YAML code for the schema: php symfony propel:build-schema Or you can write the YAML code directly, and use the Symfony command-line tool to create the SQL for accessing the database. Something along these lines creates the needed SQL to build the database: php symfony propel:build-sql To actually create the tables, follow it with: php symfony propel:insert-sql Either way gets you there. Then, you use to construct all the classes that map the records in your database tables to objects: php symfony propel:build-model Symfony’s website provides plenty of documentation. You’ll find the Getting Started tutorial and four online books. One book is an introductory guide, another is a collection of 24 daily tutorials that take you through the process of building a substantial website, another book is a reference guide, and the last covers more advanced topics. There is also a browsable API document online, as well as “screencast” demonstrations. In the short time I was able to work with Symfony, it became obvious that to really make it sing, you must become well versed in its various technologies: the Symfony framework’s API, YAML, and JavaScript. (SQL doesn’t hurt, either.) Happily, there’s lots of help along that road. The documentation is very good, and Symfony’s debugging and logging capabilities are second to none. But expect to spend more time to become proficient in Symfony than with the other frameworks. Read the reviews of other PHP frameworks: InfoWorld review: Fabulous PHP frameworks Fabulous PHP frameworks: CakePHP Fabulous PHP frameworks: CodeIgniter Fabulous PHP frameworks: Zend Framework Fabulous PHP frameworks: Qcodo, Lithium, Seagull, and Yii Also on InfoWorld: InfoWorld review: Eight PHP power tools Software DevelopmentPHP