Symfony3, a PHP framework
The Symfony framework is listed as one of the best PHP frameworks for modern web development. It has a wide developer community and many ardent fans. In this post I’ll start with introducing the framework and how to install it, then we’ll see in the coming tutorials different Symfony3 features and how to implement them.
So let’s get started with the basics !
What’s a framework ?
As simply as we can define it, a framework is an abstraction in which a certain software providing generic functionality can be selectively changed by additional user-written code. So it’s a universal, reusable software environment that provides particular functionality. Software frameworks might include support programs, compilers, code libraries, tool sets, and APIs that bring together all the different components to enable the development of a project or solution.
Frameworks, not libraries.
Given that frameworks include libraries and other components. You should be aware of confusing them with libraries as some people do. They contain the following distinguishing features:
• Inversion of control:
in a framework, unlike in libraries, the overall program’s flow of control is not dedicated by the caller, but by the framework. In other words, if you’re using a library, the objects and methods implemented by the library are instantiated and invoked by your custom application. But if you’re using a framework, you implement the objects and methods that are custom to your application and they are instantiated and invoked by the framework. A framework defines the flow of control for the application. This simple Udacity video explains it well.
• Default behavior:
a framework has a default behavior which is edited by user’s customizations. Before user’s interactions, this default behavior can be fully useful , and not just a series of no-ops as it’s the case with libraries.
a framework can be extended and specialized by user code to provide specific functionnality. Which is not possible with libraries. Also frameworks come with predefined modules (called bundles in the Symfony framework) which you can add or remove depending on your needs.
• Non-modifiable framework code:
the framework code is not supposed to be modified. Users can extend the framework, but should not modify its code.
Why a framework ?
There are various reasons for you to consider, as a beginner developer, to use a framework for your project. First thing is that frameworks can improve your productivity, as they allow you to focus on the unique requirements of your application instead of spending time on the infrastructure. They make you save time by re-using generic modules. Also, they improve the quality, reliability and robustness of your project, as they provide you with an application that is structured, maintainable and upgradable : having an application on a certain structure defined by a framework gives other developers the ability to easily “adopt” it and maintain it over time and to upgrade it both quickly and neatly, whenever necessary.
In what follows we’ll go through the details of the Symfony PHP framework.
What’s Symfony ?
Symfony is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems and can be used to build dynamic websites, web applications, web services or resources. What we call a PHP web application framework. It’s a free and open source software.
Symfony is available in different editions. For most applications, the standard edition is the most appropriate. It comes with a collection of the most commun components and includes a build-in configuration system. There also are a number of symfony distributions available. These are purpose built. For example, there is a distribution built explicitly for building content management frameworks. Also, Symfony is available as individual components. Each component has its own Git repository. You can get the code directly from there, or you can download an archive, or install it with PEAR, or with the Composer installer. Drupal 8 is an example of project that uses some Symfony components for some of its functionnalities, while it isn’t build on the Symfony framework. You can find here a list of the PHP projects that either use the full-stack Symfony framework, or some of the available components.
In our case we’re working with WampServer. We’ll need to set some configurations on wamp as a first step.
1- Set up your server ( wamp )
enable the apache rewrite_module by clicking on the WAMP icon in your task bar, navigating to the Apache > Apache Modules directory and clicking on the rewrite_module as follows :
then you’ll need to enable the php_xsl.dll extension in the php.ini configuration file: click on the WAMP icon, select the PHP folder and click on php.ini. Navigate to the php_xsl.dll extension and remove the semicolon from the line.
2- Add PHP and MySQL as windows environment variables
you will first have to note down the full path to your PHP and MySQL folders. To do this navigate to your WAMP base directory. Then add the two following values to your Path enivronment variable …/wamp/www/bin/php/phpVersion and …/wamp/www/bin/php/mysql/mysqlVersion :
3- Create a new Symfony project
• Using Composer:
Composer is the package manager used by modern PHP applications. Use Composer to manage dependencies in your Symfony applications and to install Symfony Components in your PHP projects. Follow the official documentation here to install composer.
After installing composer, execute the
create-project command to create a new Symfony application based on its latest stable version:
$ composer create-project symfony/framework-standard-edition my_project_name
• Using Netbeans IDE:
In this case you need to dowload the Symfony package, and configure the symfony framework on Netbeans going to Tools>Options>Framewoks and Tools>Symfony2/3 and adding the path to your downloaded zip file as follows:
That’s all for this introductory post on Symfony framework ! See you in the coming Symfony3 tutorials.