Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

PHP is currently one of the most popular languages in web development. Over time, the language itself has grown and become more mature. However, it still lacks good design patterns and good habits "by design". You can write a very good code with it, but you can also write very bad "spaghetti code".

Symfony2 is currently one of the most popular frameworks to speed up PHP development. It greatly helps you to create clean and reusable code, and it is the first framework that takes modern design patterns like DependencyInjection very seriously. It is also the first framework that uses features of PHP 5.3—namespaces, closures, and so on. By using this framework, you will be able to deliver more advanced and complicated web applications, suitable even for enterprise requirements.

What this book covers

Chapter 1, The Symfony Framework – Installation and Configuration, gives a quick overview of Symfony's history, ways to install and configure it, and ways to use the composer—the dependency manager used within Symfony2.

Chapter 2, Your First Pages, gives you a quick walkthrough over the basic MVC features available in most solutions nowadays. It will demonstrate to you how to create simple controllers and first views, prepare entities, and load sample data.

Chapter 3, Twig Templating and Assets Handling, shows you in details how to handle views, assets managements, and add a frontend library.

Chapter 4, Forms, focuses on form creation. It will show you how to create form types, validate forms, and write data to databases.

Chapter 5, Security and Handling Users, gives you information about Symfony security features. In this chapter, we will create an example of registration and login forms, and how to handle users with the help of an open source bundle.

Chapter 6, Translation, gives information about translation and internalization. You will learn how to create translation files, translate various areas of your application, and choose a good translation strategy.

Chapter 7, AJAX, teaches you how to handle basic AJAX calls. We will also learn about bundles that are useful when you write RESTful applications, how to handle various HTTP methods, and how to serialize data in a JSON structure.

Chapter 8, Command-line Operations, will provide you with examples on how to create a command-line task, which is often useful with tasks executed in background (cron tasks). You will also learn how to send an e-mail through swiftmailer—a component used by default within the Symfony framework to handle e-mail sending.

Chapter 9, Symfony2 Profiler and Debugger, is where you will learn about the Web Debug Toolbar and profiler. We will examine the possibilities offered by these tools and write some code to demonstrate debugging and profiling features.

Chapter 10, Preparing an Application for Production, will give you an overview of the tasks that are usually done when your project needs to be deployed. You will also get an overview of various deployment strategies, and you will be able to check your framework and bundles against known security issues.

What you need for this book

You will need a minimum of a PHP 5.4 installation with standard extensions such as database, intl, mcrypt, posix, or pcntl. It is also recommended for this book to use a Unix/Linux system such as Debian, Ubuntu, Red Hat, FreeBSD, or Mac OS X.

Who this book is for

This book is aimed at experienced programmers, especially those familiar with a closely related technology such as Yii or Laravel but who now want to learn Symfony quickly.

This book will also prove beneficial for experienced PHP developers who want to explore and evaluate new frameworks and their possibilities in day-to-day tasks.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Your own bundles are usually stored within the src/ directory, while the third-party bundles sit within the vendor/ directory."

A block of code is set as follows:

public function indexAction()
    {
        return $this->render('default/index.html.twig');
    }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

use AppBundle\Entity\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

Any command-line input or output is written as follows:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You should see a Hello anonymous! welcome text."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.