|Published (Last):||2 July 2018|
|PDF File Size:||6.50 Mb|
|ePub File Size:||20.95 Mb|
|Price:||Free* [*Free Regsitration Required]|
The symfony framework has been an Open-Source project for more than four years and has become one of the most popular PHP frameworks thanks to its great features and great documentation. This book describes the creation of a web application with the symfony framework, step-by-step from the specifications to the implementation.
It is targeted at beginners who want to learn symfony, understand how it works, and also learn about the best web development practices.
The application to be designed could have been yet another blog engine. But we want to use symfony on a useful project. The goal is to demonstrate that symfony can be used to develop professional applications with style and little effort. We will keep the content of the project secret for another day as we already have much for now. However, let's give it a name: Jobeet. Each day of this book is meant to last between one and two hours, and will be the occasion to learn symfony by coding a real website, from start to finish.
Every day, new features will be added to the application, and we'll take advantage of this development to introduce you to new symfony functionalities as well as good practices in symfony web development. Remember the early days of PHP4.
Ah, la Belle Epoque! PHP was one of the first languages dedicated to the web and one of the easiest to learn. But as web technologies evolve at a very fast pace, web developers need to keep up with the latest best practices and tools. The best way to learn is of course by reading blogs, tutorials, and books. We have read a lot of these, be they written for PHP, Python, Java, Ruby, or Perl, and many of them fall short when the author starts giving snippets of codes as examples.
These things are serious business. They are perhaps the most important part of any piece of code. And as a reader, you are left alone. Without these concerns taken into account, the examples are much less useful. You cannot use them as a good starting point.
That's bad! Because security, validation, error handling, and tests, just to name a few, take care to code right. In this book, you will never see statements like those as we will write tests, error handling, validation code, and be sure we develop a secure application. That's because symfony is about code, but also about best practices and how to develop professional applications for the enterprise.
We will be able to afford this luxury because symfony provides all the tools needed to code these aspects easily without writing too much code. Validation, error handling, security, and tests are first-class citizens in symfony, so it won't take us too long to explain. This is just one of many reasons why to use a framework for "real life" projects. All the code you will read in this book is code you could use for a real project. We encourage you to copy and paste snippets of code or steal whole chunks.
We won't write PHP code. But even without writing a single line of code, you will start understanding the benefits of using a framework like symfony, just by bootstrapping a new project.
The objective of this day is to setup the development environment and display a page of the application in a web browser. This includes installation of symfony, creation of an application, and web server configuration.
As this book will mostly focus on the symfony framework, we will assume that you already have a solid knowledge of PHP 5 and Object Oriented programming.
Before installing symfony, you need to check that your computer has everything installed and configured correctly. Take the time to conscientiously read this day and follow all the steps required to check your configuration, as it may save your day further down the road. First of all, you need to check that your computer has a friendly working environment for web development. The symfony framework comes bundled with a command line tool that automates a lot of work for you.
If you are a Unix-like OS user, you will feel right at home. If you run a Windows system, it will also work fine, but you will just have to type a few commands at the cmd prompt. Unix shell commands can come in handy in a Windows environment. If you would like to use tools like tar , gzip or grep on Windows, you can install Cygwin. The adventurous may also like to try Microsoft's Windows Services for Unix.
As PHP configurations can vary a lot from one OS to another, or even between different Linux distributions, you need to check that your PHP configuration meets the symfony minimum requirements.
First, ensure that you have PHP 5. Be aware that on some configurations, you might have two different PHP versions installed: one for the command line, and another for the web. Save the script somewhere under your current web root directory. Launch the configuration checker script from the command line:. If there is a problem with your PHP configuration, the output of the command will give you hints on what to fix and how to fix it.
You should also execute the checker from a browser and fix the issues it might discover. That's because PHP can have a distinct php. Before installing symfony, you first need to create a directory that will host all the files related to Jobeet:. Windows users are advised to run symfony and to setup their new project in a path which contains no spaces.
Avoid using the Documents and Settings directory, including anywhere under My Documents. If you create the symfony project directory under the web root directory, you won't need to configure your web server. Of course, for production environments, we strongly advise you to configure your web server as explained in the web server configuration section.
Now, you need to install symfony. As the symfony framework has several stable versions, you need to choose the one you want to install by reading the installation page on the symfony website.
You can install symfony globally on your machine, or embed it into each of your project. The latter is the recommended one as projects will then be totally independent from each others.
Upgrading your locally installed symfony won't break some of your projects unexpectedly. It means you will be able to have projects on different versions of symfony, and upgrade them one at a time as you see fit. So, first, create this directory:. The easiest way to install symfony is to download the archive for the version you choose from the symfony website. Go to the installation page for the version you have just chosen, symfony 1.
Under the " Source Download " section, you will find the archive in. Under Windows, unzipping the zip file can be achieved using Windows Explorer. If everything goes well, this command will run your favorite editor to give you the opportunity to configure the external Subversion sources. Whenever a new release comes out as announced on the symfony blog , you will need to change the URL to the new version. Using the branch makes your project benefits from the bug fixes automatically whenever you run a svn update.
Now that symfony is installed, check that everything is working by using the symfony command line to display the symfony version note the capital V :.
If you are curious about what this command line tool can do for you, type symfony to list the available options and tasks:. The symfony command line is the developer's best friend. It provides a lot of utilities that improve your productivity for day-to-day activities like cleaning the cache, generating code, and much more.
In symfony, applications sharing the same data model are regrouped into projects. For most projects, you will have two different applications: a frontend and a backend. The generate:project task generates the default structure of directories and files needed for a symfony project:. Why does symfony generate so many files?
One of the main benefits of using a full-stack framework is to standardize your developments. Thanks to symfony's default structure of files and directories, any developer with some symfony knowledge can take over the maintenance of any symfony project.
In a matter of minutes, he will be able to dive into the code, fix bugs, and add new features. The generate:project task has also created a symfony shortcut in the project root directory to shorten the number of characters you have to write when running a task. So, from now on, instead of using the fully qualified path to the symfony program, you can use the symfony shortcut.
Because the symfony shortcut file is executable, Unix users can replace all occurrences of ' php symfony ' by '. On Windows you can copy the ' symfony. By default, the generate:app task has secured our application from the two most widespread vulnerabilities found on the web.
That's right, symfony automatically takes security measures on our behalf. The content of these directories should be ignored by your SCM by editing the svn:ignore property if you use Subversion for instance. If you have created the project directory it somewhere under the web root directory of your web server, you can already access the project in a web browser.
If the user knows that your website is developed with symfony, he will have access to a lot of sensitive files. Never ever use this setup on a production server , and read the next section to learn how to configure your web server properly.
All other PHP files can be hidden from the browser, which is a good idea as far as security is concerned. Now it is time to change your Apache configuration, to make the new project accessible to the world.
Locate and open the httpd. This configuration makes Apache listen to port on your machine, so, after restarting apache, the website will be accessible at the following URL:. You can change to any number, but favour numbers greater than as they do not require administrator rights.
Day 1: Starting up the Project
Subscribe to RSS
The symfony framework has been an Open-Source project for more than four years and has become one of the most popular PHP frameworks thanks to its great features and great documentation. This book describes the creation of a web application with the symfony framework, step-by-step from the specifications to the implementation. It is targeted at beginners who want to learn symfony, understand how it works, and also learn about the best web development practices. The application to be designed could have been yet another blog engine. But we want to use symfony on a useful project. The goal is to demonstrate that symfony can be used to develop professional applications with style and little effort. We will keep the content of the project secret for another day as we already have much for now.
PRACTICAL SYMFONY JOOBET