Symfony is an object-oriented PHP5 framework based on the MVC model. Symfony allows for the separation of business rules, server logic and presentation views of a web application. It also contains numerous tools and classes aimed at shortening the development time of a complex web application.


What is a framework?


A framework adds new mechanisms on top of a programming language, and these mechanisms automate many of the development patterns used for a given purpose. A framework also adds structure to the code, and pushes the developer to write better, more readable and maintainable code. A framework also makes programming easier, since it packages complex operations into simple statements.


A framework is usually developed with the same language that it extends. A PHP5 framework is a set of files written in PHP5.


A framework will add layering to an application. In general, they divide applications in three layers:


  • The presentation logic handles the interactions between the user and the software
  • 表现层逻辑 处理用户和应用程序之间的交互。
  • The data source logic carries the access to a database or other data providers
  • 数据源逻辑 处理所有与数据库或者其他数据提供者的交互。
  • The domain logic , or business logic, is the remaining piece. It involves calculation made on inputs, manipulation of data from the presentation, and dispatching of data source logic according to the commands received from the presentation.
  • 领域逻辑 ,或者叫业务逻辑,这是留下来让你填写的地方。它包括计算用户输入,处理表现层的数据,根据表现层命令执行相应的数据源逻辑等。

Web application frameworks intend to facilitate the development of… web applications (websites, Intranets, etc.). Building a basic dynamic website can be easily achieved with existing programming languages, and PHP is known for its simplicity and broadly adopted for that purpose. With PHP alone, you can already query a database, manage session cookies, access files in the server, etc. But when it comes to building a more complex website, where business logic increases the volume of code to maintain, the need of a web application framework arises.

Web应用程序框架的目的就是想要简化各种Web应用程序的开发(包括网站,内网应用程序等)。用现存的编程语言当然可以比较轻松的建造基本的动态网站,比如PHP就是因其的简单性和广泛采用性而被大家所熟知。仅用PHP,你就可以查询数据库,管理session cookies,访问服务器上的文件,等等。但是,当你需要开发一个比较复杂的网站时,当由于业务代码的激增而导致有大量代码需要维护时,web应用程序框架的重要性就体现出来。

What is symfony?


Symfony is a complete framework designed to help and speedup the development of web applications.


It is based on the following concepts:


  • compatible with as many environments as possible
  • 尽可能的兼容所有的应用环境
  • easy to install and configure
  • 简单安装和配置
  • simple to learn
  • 易于学习
  • enterprise ready
  • 支持企业开发
  • convention rather than configuration, supporting fallback calls
  • 依靠惯例而不是配置,支持回滚调用[i1]
  • simple in most cases, but still flexible enough to adapt to complex cases
  • 尽量使多数情况简单,但是当需要复杂时,依然能够支持
  • most common web features included
  • 包括大多数通用的web特性
  • compliant with most of the web “best practices” and web “design patterns”
  • 遵从大多数的web最佳实践和web设计模式
  • very readable code with easy maintenance
  • 非常易读的代码,非常高的可维护性
  • open source
  • 开源

The main concept underlying the symfony framework is that the most common tasks are done automatically so that the developer can focus entirely on the specifics of an application. There is no need to reinvent the wheel every time a new web application is built.


To fulfill these requirements, symfony was written entirely in PHP5. It has been thoroughly tested in various real world projects, and is actually in use for high demand e-business websites. It is compatible with most of the available databases, among which:


  • MySQL
  • PostgreSQL
  • Oracle
  • and any other database if a Creole driver exists for it
  • 任何其他的数据库,只要它具备Creole驱动

The symfony object model relies on three distinct layers:


  • a database abstraction
  • 一个数据库抽象层
  • an object-relational mapping
  • 一个对象-关系映射层
  • a Model-View-Controller model for the front and back-office
  • 一个Model-View-Controller模型用来支持前端和后端的应用

Common features of web projects are made easy since Symfony natively automates them:


  • internationalization
  • 国际化
  • templating with helpers
  • templating with helpers


  • form validation
  • 表单验证
  • cache management
  • 缓存管理
  • shopping cart management
  • 购物车管理
  • smart URLs
  • 智能URLs
  • Scaffolding
  • Scaffolding


  • email sending
  • 邮件发送
  • Pagination
  • 分页支持
  • AJAX


  • Ajax式交互

In addition, to fulfill the requirements of enterprises having their own coding guidelines and project management rules, symfony can be entirely reconfigured using YAML configuration files. It provides by default, several development environments, and is bundled with tools to easily achieve the following operations:


  • prototyping
  • prototyping


  • content management
  • 内容管理
  • live configuration changes
  • 在线配置变更
  • deployment
  • 部署
  • unit testing
  • 单元测试
  • applicative testing
  • 可用性测试
  • logging
  • logging


  • debugging
  • 调试

Symfony uses some code fragments of other open source projects:


  • Creole, for the database abstraction layer
  • Creole,为数据抽象层
  • Propel, for the object-relational mapping layer
  • Propel,为对象-关系映射层
  • Mojavi, for the Model-View-Controller model layer
  • Mojavi,为Model-View-Controller模型层

Is symfony made for me?

Symfony** 适合我吗?**

Whether you are a PHP5 expert or a beginner in web application programming doesn’t matter. The main factor that should direct your decision is the size of your project.


If you want to develop a simple website with five to ten pages, having limited access to a database and no obligation for performance, availability or documentation, then you should stick with PHP alone. You wouldn’t take much advantage of the features of a web application framework, and using object orientation or a MVC model would only slow down your development. Symfony is not optimized to run efficiently on a shared server with only CGI support.


On the other hand, if you develop bigger web applications, with a heavy business logic, PHP alone is not enough. If you plan to maintain or extend your application in the future, you will need your code to be lightweight, readable and performant. If you want to use the latest advances in user interaction (like AJAX) in an intuitive way, you can’t just write hundreds of lines of Javascript. If you want to have fun and develop fast, then PHP alone will probably be disappointing. For all these cases, symfony is made for you.


And of course, if you are a profesional web developer, you already know all the benefits of web application frameworks, and you need one which is mature, well documented, and with a large community. Search no more, for symfony is your solution.


Translated by coofucoo