Symfony_cookbook_2.1.pdf
(
1779 KB
)
Pobierz
The Cookbook
for Symfony 2.1
generated on January 8, 2013
The Cookbook
(2.1)
This work is licensed under the “Attribution-Share Alike 3.0 Unported” license (
http://creativecommons.org/
licenses/by-sa/3.0/
).
You are free
to share
(to copy, distribute and transmit the work), and
to remix
(to adapt the work) under the
following conditions:
•
Attribution
: You must attribute the work in the manner specified by the author or licensor (but
not in any way that suggests that they endorse you or your use of the work).
•
Share Alike
: If you alter, transform, or build upon this work, you may distribute the resulting work
only under the same, similar or a compatible license. For any reuse or distribution, you must make
clear to others the license terms of this work.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor SensioLabs shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by
the information contained in this work.
If you find typos or errors, feel free to report them by creating a ticket on the Symfony ticketing system
(
http://github.com/symfony/symfony-docs/issues
).
Based
on
tickets
and
users
feedback,
this
book
is
continuously updated.
Contents at a Glance
How to Create and store a Symfony2 Project in git ...............................................................................5
How to Create and store a Symfony2 Project in Subversion ..................................................................9
How to customize Error Pages ........................................................................................................... 13
How to define Controllers as Services ................................................................................................ 15
How to force routes to always use HTTPS or HTTP ........................................................................... 17
How to allow a "/" character in a route parameter .............................................................................. 18
How to configure a redirect to another route without a custom controller........................................... 19
How to use HTTP Methods beyond GET and POST in Routes........................................................... 20
How to use Service Container Parameters in your Routes ................................................................... 22
How to Use Assetic for Asset Management ........................................................................................ 24
How to Minify JavaScripts and Stylesheets with YUI Compressor....................................................... 29
How to Use Assetic For Image Optimization with Twig Functions ..................................................... 31
How to Apply an Assetic Filter to a Specific File Extension................................................................. 34
How to handle File Uploads with Doctrine ........................................................................................ 36
How to use Doctrine Extensions: Timestampable, Sluggable, Translatable, etc. .................................. 44
How to Register Event Listeners and Subscribers ............................................................................... 45
How to use Doctrine's DBAL Layer ................................................................................................... 47
How to generate Entities from an Existing Database........................................................................... 49
How to work with Multiple Entity Managers and Connections........................................................... 53
How to Register Custom DQL Functions........................................................................................... 56
How to Define Relationships with Abstract Classes and Interfaces...................................................... 57
How to implement a simple Registration Form .................................................................................. 60
How to customize Form Rendering ................................................................................................... 66
How to use Data Transformers .......................................................................................................... 77
How to Dynamically Generate Forms Using Form Events .................................................................. 83
How to Embed a Collection of Forms ................................................................................................ 86
How to Create a Custom Form Field Type......................................................................................... 98
How to Create a Form Type Extension ............................................................................................ 103
How to use the Virtual Form Field Option....................................................................................... 108
How to create a Custom Validation Constraint ................................................................................ 111
How to Master and Create new Environments ................................................................................. 115
How to override Symfony's Default Directory Structure.................................................................... 120
How to Set External Parameters in the Service Container ................................................................. 123
How to use PdoSessionHandler to store Sessions in the Database ..................................................... 126
How to use the Apache Router ........................................................................................................ 129
How to create an Event Listener ...................................................................................................... 131
PDF brought to you by
generated on January 8, 2013
Contents at a Glance | iii
How to work with Scopes ............................................................................................................... 134
How to work with Compiler Passes in Bundles ................................................................................ 137
How to use Best Practices for Structuring Bundles............................................................................ 138
How to use Bundle Inheritance to Override parts of a Bundle ........................................................... 143
How to Override any Part of a Bundle ............................................................................................. 146
How to expose a Semantic Configuration for a Bundle ..................................................................... 149
How to send an Email ..................................................................................................................... 158
How to use Gmail to send Emails .................................................................................................... 161
How to Work with Emails During Development .............................................................................. 162
How to Spool Emails....................................................................................................................... 164
How to simulate HTTP Authentication in a Functional Test ............................................................ 166
How to test the Interaction of several Clients ................................................................................... 167
How to use the Profiler in a Functional Test..................................................................................... 168
How to test Doctrine Repositories ................................................................................................... 170
How to customize the Bootstrap Process before running Tests.......................................................... 172
How to load Security Users from the Database (the Entity Provider) ................................................. 174
How to add "Remember Me" Login Functionality ............................................................................ 185
How to implement your own Voter to blacklist IP Addresses............................................................ 188
How to use Access Control Lists (ACLs) .......................................................................................... 191
How to use Advanced ACL Concepts .............................................................................................. 195
How to force HTTPS or HTTP for Different URLs ........................................................................... 199
How to customize your Form Login ................................................................................................ 200
How to secure any Service or Method in your Application................................................................ 203
How to create a custom User Provider ............................................................................................. 207
How to create a custom Authentication Provider ............................................................................. 212
How to change the Default Target Path Behavior ............................................................................. 221
How to use Varnish to speed up my Website ................................................................................... 223
How to Inject Variables into all Templates (i.e. Global Variables) ..................................................... 225
How to use PHP instead of Twig for Templates ............................................................................... 227
How to write a custom Twig Extension ........................................................................................... 232
How to render a Template without a custom Controller................................................................... 235
How to use Monolog to write Logs .................................................................................................. 236
How to Configure Monolog to Email Errors .................................................................................... 240
How to log Messages to different Files ............................................................................................. 242
How to create a Console Command ................................................................................................ 244
How to use the Console .................................................................................................................. 247
How to generate URLs and send Emails from the Console................................................................ 249
How to enable logging in Console Commands ................................................................................. 251
How to optimize your development Environment for debugging ...................................................... 256
How to setup before and after Filters ............................................................................................... 258
How to extend a Class without using Inheritance............................................................................. 262
How to customize a Method Behavior without using Inheritance...................................................... 265
How to register a new Request Format and Mime Type.................................................................... 267
How to create a custom Data Collector............................................................................................ 269
How to Create a SOAP Web Service in a Symfony2 Controller ......................................................... 272
How Symfony2 differs from symfony1 ............................................................................................. 276
How to deploy a Symfony2 application............................................................................................ 281
Contents at a Glance | 4
iv | Contents at a Glance
Chapter 1
How to Create and store a Symfony2 Project in
git
Though this entry is specifically about git, the same generic principles will apply if you're storing
your project in Subversion.
Once you've read through
Creating Pages in Symfony2
and become familiar with using Symfony, you'll
no-doubt be ready to start your own project. In this cookbook article, you'll learn the best way to start a
new Symfony2 project that's stored using the
git
1
source control management system.
Initial Project Setup
To get started, you'll need to download Symfony and initialize your local git repository:
1.
Download the
Symfony2 Standard Edition
2
without vendors.
2.
Unzip/untar the distribution. It will create a folder called Symfony with your new project
structure, config files, etc. Rename it to whatever you like.
Create a new file called
.gitignore
at the root of your new project (e.g. next to the
composer.json
file) and paste the following into it. Files matching these patterns will be
ignored by git:
3.
1
2
3
4
5
6
/web/bundles/
/app/bootstrap*
/app/cache/*
/app/logs/*
/vendor/
/app/config/parameters.yml
Listing 1-1
1.
http://git-scm.com/
2.
http://symfony.com/download
PDF brought to you by
generated on January 8, 2013
Chapter 1: How to Create and store a Symfony2 Project in git | 5
Plik z chomika:
ebookipdf
Inne pliki z tego folderu:
11.scm
(10345 KB)
raport-ehandel-polska-2012.pdf
(10966 KB)
coreftplite.exe
(4644 KB)
techniki-skutecznej-sprzedazy-przez-telefon-i-internet.pdf
(342 KB)
nauka-sukcesu-new.pdf
(220 KB)
Inne foldery tego chomika:
5 najlepszych zamknięć sprzedaży kurs audiobook
Aishwarya Rai pictures
audiobooki
Ayesha Takia pictures
biznes-ebooki
Zgłoś jeśli
naruszono regulamin