Join Jon Peck for an in-depth discussion in this video What is Symfony, and why should I use it?, part of Up and Running with Symfony2 for PHP (2014).
- As a developer, it's important to know what tools are available to help you solve problems and build awesome things. Symfony 2 is a tool but knowing exactly what a tool is and what it does gives context for making decisions about whether or not it's the right choice for a job. Therefore, let's start by defining exactly what Symfony is. Symfony is a PHP web application framework that can be used to build dynamic websites, web applications, web services and resources. Symfony uses the MVC architectural pattern for its internal code structure and layout, which separates the data model with business logic from the user interface.
I'll talk more about MVC architecture in the next segment. Symfony is free and open-source software. It's freely licensed using the MIT license which basically says it can be used in proprietary software as long as there's a copy of the license with it. Open-source means that the source code can be shared in its entirety for reference, improvements, and collaborations. Symfony is a framework, so a logical question would be, "Why should anybody use a coding framework?" One of the primary features is code organization that goes well beyond just how the code itself is formatted.
By using a standardized layout for the structure of the code and how the pieces interact with one other, the source code is easier to work with and scale. From experience, if you've ever gotten used to a framework and went back to work on an ad hoc project, the difference can be painful. Frameworks also offer reusable components that perform common tasks. Why reinvent the wheel when there's a perfectly good wheel that thousands of people have crafted and refined? Reusing components means less code to work on, which is less work, less overhead, and more focus on developing features that deliver value.
Frameworks also provide built-in security and scalability. For example, when using a good framework, mundane tasks like filtering and validating user input are built-in, of course, never trust user input, but many use cases and edge scenarios have been designed for and tested, something that can take a fantastic amount of time to do yourself. For scalability, frameworks are designed to grow upwards and outwards, which provides a stable structure that you can rely on, no matter what the size of your application or the traffic is.
Okay, so this all sounds good on paper, but do you need a framework? Ultimately you're the only person that can make that choice. However, consider the advantages. By avoiding reinventing the wheel, you can focus on whatever task is at hand. Applications designed using frameworks are easier to maintain and grow for a number of reasons. The common code structure enables collaboration. If someone else knows the framework that the application was built in, they can use their understanding of the structure to quickly adapt and contribute.
Also, it's simple to upgrade a framework within an application which provides bug fixes, new functionality, and security enhancements. At the end of the day, it's technically not necessary to use a framework, however, I, and many others, strongly recommend using a framework within any application. Symfony is a framework, and it's absolutely not the only framework out there. With that said, why use Symfony? Well, it's a full stack framework, meaning it's a complete solution for just about any kind of application. 'Course, no size fits all, but Symfony will fit most by containing most of the different libraries that are useful in many different contexts.
As a framework, Symfony also provides a mechanism for gluing the disparate pieces together so you can work with the individual components as a complete whole. Symfony's a very flexible framework that can be used in many different kinds of applications. Big or small, user-facing or providing a restful service, and so forth. It's also very modular, to the point that you don't have to use the entire framework if you don't want to, only bits and pieces if you're so inclined. Symfony is an incredibly stable framework in a number of ways.
The entire system includes a rigorous series of automated unit tests for functionality, bugs and backwards compatibility and so forth. Only changes that pass the test are included in the framework. Additionally, Symfony has a regular release cycle, which is a normalized versioning system and a support schedule. You can rely on the viability of any particular version of Symfony, which matters, specially when you're determining how to support an application. Finally, Symfony is a mature framework with major versions being available since 2007.
It's incredibly well documented, both online and offline with a very active development and support community. Symfony is available in a number of different editions. For most applications, the standard edition is the most appropriate. Standard comes with a collection of the most common components, ready to go, and includes a built-in configuration system that we're gonna be using. There are also a number of Symfony distributions available, think of them like starter kits. Similar to Linux distributions, Symfony distributions are purpose-built with a particular goal in mind.
For example, there's a distribution designed explicitly for building content management frameworks. Finally, Symfony is available as individual components, not just as a collection. Each component is a decoupled collection of standard features, meaning that a component doesn't actually have to be interacting with Symfony, they're all stand-alone. For example, Triple 8 uses Symfony components for some of its functionality, but Triple 8 isn't built on the Symfony framework. Within the various editions, Symfony has a highly structured versioning system.
Symfony version 2 is the current major version, with minor versions being released on a schedule of every six months. Each minor version is supported with eight months of bug fixes, and 14 months of security fixes. Symfony also provides long term support, or LTS versions that are released every two years. Each LTS version provides an entire three years of bug fixes and four of security fixes. That's something that can be relied on, and definitely something to consider when choosing which version to use.
The upgrade process between minor versions, such as 2.4 to 2.5 is very well documented. Symfony includes a lot of instructions, and details on what changed between each minor version, which makes it easy to upgrade, incrementally between each release. As you can imagine, there's a lot of choice when it comes to Symfony. So, which particular combination of Symfony will we be using for this course? The best place to start is with Symfony Standard Edition, which is the current minor release, version 2.5.
The scope of what we're going to be doing should be easily forwards-compatible with future minor versions within two, such as 2.6, 2.7, and so forth. However, if you're going to be using a newer version, check the upgrade documentation, just in case there are any differences. Earlier, I mentioned that Symfony uses an MVC architecture, but what does that mean?
- Installing Symfony
- Creating a bundle from the console
- Customizing and generating database tables
- Generating controllers
- Creating, editing, and debugging entities
- Displaying and debugging a form
- Rendering content with templates
Skill Level Intermediate
Q: When trying to access the application, I receive an error stating "This script is only accessible from localhost." How can I get around this restriction?
A: The development front controller and configuration scripts are protected by default to only allow access from the localhost. Refer to the video titled “Exploring the Symfony layout” to see how to disable this security.