O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Symfony2 Essentials

Book Description

A fast-paced developer's guide to using Symfony2 to make your everyday web development work more efficient

About This Book

  • Build web applications with the latest features of Symfony2
  • Focus on common tasks such as creating CRUD, creating an API, and providing a login
  • Install and configure Symfony2 and evaluate it for your everyday needs

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.

What You Will Learn

  • Familiarise yourself with the Symfony framework, its latest features, and how to install it
  • Discover the concept of bundles and their application
  • Handle translations within Symfony, enable translations, and learn how to handle database translations
  • Understand Symfony's security model, how to secure applications, and implement a custom authentication provider by using FOSUserBundle
  • Explore the use of Twig, find best practices around its usage, and discover its common pitfalls
  • Create internal commands that will handle sending e-mail reminders for your app
  • Develop a plugin for the profiler to provide custom information about your application
  • Deploy applications based on Symfony2 using various methods including simple FTP copying, rsync, CI deployment, and more

In Detail

Symfony is a free and open source PHP MVC web application development framework, which helps you create and maintain web applications and replace recurrent coding tasks. It integrates with an independent library, PHPUnit, to give you a rich testing framework. It is one of the best and most popular frameworks available on the market. Popular projects such as Drupal, Laravel, and phpBB also use Symfony. Its well-organized structure, clean code, and good programming practices make web development a breeze.

Symfony2 Essentials will guide you through the process of creating a sample web application with Symfony2. You will create a To-Do application, using a few of the most commonly used Symfony2 components, and discover how to perform these development tasks efficiently.

This book introduces you to the Symfony framework with a quick installation guide and a brief explanation of its key features including the MVC architecture, twig templating, dependency injection, and more. You will learn to manage dependencies, create controllers, views, and API calls, and secure your application.

Next, you will go through the steps that are common for most web applications, which include writing CRUD and AJAX, handling forms, validation, translations, and the command-line interface, and e-mail sending features. The book ends with best practices, debugging, profiling, and deployment procedures.

By the end of this book, you will have learned how to combine a Symfony2 framework with other open source code to speed up the development process.

Style and approach

A fast-paced, step-by-step guide with examples on how to write the most common pieces of code while developing typical web applications with Symfony.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. 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.

Table of Contents

  1. Symfony2 Essentials
    1. Table of Contents
    2. Symfony2 Essentials
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. The Symfony Framework – Installation and Configuration
      1. Key reasons to choose Symfony2
      2. The history of Symfony
      3. Installation
      4. Installing Symfony2 using an installer
      5. The Symfony2 directory structure
        1. What is a bundle?
        2. Composer
      6. The configuration files
      7. The Symfony2 console
      8. Summary
    9. 2. Your First Pages
      1. Everything is a bundle
      2. The configuration format
      3. Cleanups
        1. Recreating AppBundle
      4. Routing
      5. Templates – the View layer
      6. Entities – the Model layer
      7. Migrations
      8. Fixtures
      9. Summary
    10. 3. Twig Templating and Assets Handling
      1. The Twig templating engine
        1. Assets management
          1. Assetic
          2. Handling third-party bundle assets
          3. Handling your application assets
      2. Creating a list of tasks
      3. Summary
    11. 4. Forms
      1. Form creation
      2. Validation and form processing
      3. Theming form elements
      4. Transforming data
      5. Summary
    12. 5. Security and Handling Users
      1. Security handling
      2. Installing the user manager bundle
      3. User registration
      4. Summary
    13. 6. Translation
      1. Translations
        1. Using translations in a controller
        2. Translation file formats
        3. Variables and pluralization
        4. The translation strategy
        5. Using translation keys
        6. Database translations
      2. Summary
    14. 7. AJAX
      1. Installing and configuring REST features
        1. FOSRestBundle
        2. NelmioApiDocBundle
        3. FOSJSRoutingBundle
        4. Refactoring the existing code
        5. Adding a new controller
        6. Setting up routing and JavaScript
      2. Summary
    15. 8. Command-line Operations
      1. Creating the console command
      2. Swiftmailer
      3. Logging
      4. Summary
    16. 9. Symfony2 Profiler and Debugger
      1. The Web Debug Toolbar
      2. The Symfony2 profiler
        1. The profiler sections
        2. VarDumper
        3. The AJAX requests
      3. Data collectors
      4. The stopwatch component
      5. Summary
    17. 10. Preparing an Application for Production
      1. Preparing an application
        1. Checking the code against debug code
        2. Customizing error pages
        3. Verifying the production server requirements
        4. Security check
        5. Updating the basic assets and metadata
        6. Changing the web root directory
      2. Deployment strategies
        1. FTP
        2. The rsync deployment
        3. Continuous integrations
        4. Deployment tools
        5. Platform as a Service deployment
      3. Summary
    18. Index