Using Zend Framework 2
Using Zend Framework 2
The book about Zend Framework 2 that is easy to read and understand for beginners
About the Book
The "Using Zend Framework 2" is a book about programming websites with Zend Framework 2. With this e-Book, you can save your time and efforts learning ZF2.
The author strives to give material starting with simple things that a beginner should understand. Advanced things go last in a chapter. This makes this book the first Zend Framework book that is easy to read and understand for a newbie.
This ZF2 book's text is illustrated with code samples (the source code is published on GitHub). Each sample is a complete web-site you can install and run yourself to see Zend Framework 2 in action. You can even use the samples as a base for your own web sites.
Table of Contents
-
Preface
- Why to Read this Book?
- Zend Framework Explained
- See ZF2 Wider
- ZF2 Book for Beginners
- Structure of the Book
- Learn ZF2 by Example
- Book Reviews
- Testimonials
- Your Feedback
- Acknowledgements
-
1. Introduction to Zend Framework 2
- 1.1 What is Zend Framework 2?
- 1.2 License
- 1.3 What Companies Prefer Zend Framework 2?
- 1.4 Distributions
- 1.5 User Support
- 1.6 Supported Operating Systems
- 1.7 Server Requirements
- 1.8 Security
- 1.9 Performance
- 1.10 Design Patterns
- 1.11 Components
- 1.12 ZF2 Service Components
-
1.13 Differences with Zend Framework 1
- 1.13.1 Backwards Compatibility
- 1.13.2 ZFTool
- 1.13.3 Modules
- 1.13.4 Aspect Oriented Design
- 1.13.5 Namespaces
- 1.13.6 Configuration
- 1.13.7 Service Manager
- 1.14 Competing Frameworks
- 1.15 Summary
-
2. Zend Skeleton Application
- 2.1 Getting Zend Skeleton Application
- 2.2 Typical Directory Structure
- 2.3 Installing Dependencies with Composer
- 2.4 Apache Virtual Host
- 2.5 Opening the Web Site in Your Browser
- 2.6 Creating NetBeans Project
- 2.7 Hypertext Access File (.htaccess)
- 2.8 Blocking Access to the Web Site by IP Address
- 2.9 HTTP Authentication
- 2.10 Having Multiple Virtual Hosts
- 2.11 Hosts File
-
2.12 Advanced Composer Usage
- 2.12.1 Package Names and Versions
- 2.12.2 Installing and Updating Packages
- 2.12.3 Virtual Packages
- 2.12.4 Composer and Version Control Systems
- 2.13 Summary
-
3. Web Site Operation
- 3.1 PHP Namespaces
- 3.2 PHP Interfaces
- 3.3 PHP Class Autoloading
- 3.4 PSR-0 Standard
- 3.5 HTTP Request and Response
- 3.6 Site Entry Script
- 3.7 Events & Application’s Life Cycle
-
3.8 Application Configuration
- 3.8.1 Application-Level Config Files
- 3.8.2 Application-Level Extra Config Files
- 3.8.3 Module-Level Config Files
- 3.8.4 Combining the Configuration Files
- 3.9 Module Entry Point
-
3.10 Class Autoloading in Zend Framework 2
- 3.10.1 Composer-provided Autoloader
-
3.10.2
Zend\Loader
Component- 3.10.2.1 Standard Autoloader
- 3.10.2.2 PSR-0 and Src Directory Structure
- 3.10.2.3 Class Map Autoloader
-
3.11 Service Manager
- 3.11.1 Service Locator
- 3.11.2 Canonical Service Names
- 3.11.3 Registering a Service
- 3.11.4 Registering Invokable Classes
- 3.11.5 Registering Factories
- 3.11.6 Registering Service Aliases
- 3.11.7 Service Manager Configuration
- 3.12 Summary
-
4. Model-View-Controller
- 4.1 Get the Hello World Example from GitHub
- 4.2 Separating Business Logic from Presentation
-
4.3 Controllers
- 4.3.1 Base Controller Class
- 4.3.2 Retrieving Data from HTTP Request
- 4.3.3 Retrieving GET or POST Variables
- 4.3.4 Putting Data to HTTP Response
- 4.4 Variable Containers
- 4.5 Controller Registration
- 4.6 When to Create a New Controller?
-
4.7 Controller Plugins
- 4.7.1 Writing Own Controller Plugin
- 4.8 Views
- 4.9 View Helpers
- 4.10 View Template Names & View Resolver
- 4.11 Disabling the View Rendering
- 4.12 Error Pages
- 4.13 Models
-
4.14 Model Types
- 4.14.1 Entities
- 4.14.2 Value Objects
- 4.14.3 Services
- 4.14.4 Factories
- 4.14.5 Repositories
- 4.15 Determining the Correct Model Type
-
4.16 Skinny Controllers, Fat Models, Simple Views
- 4.16.1 Skinny Controllers
- 4.16.2 Fat Models
- 4.16.3 Simple View Templates
- 4.17 Summary
-
5. URL Routing
- 5.1 URL Structure
- 5.2 Route Types
-
5.3 Combining Route Types
- 5.3.1 Simple Route Stack
- 5.3.2 Tree Route Stack
-
5.4 Routing Configuration
- 5.4.1 Configuration for Simple Routes
- 5.4.2 Configuration for Nested Routes
- 5.4.3 Default Routing Configuration in Zend Skeleton Application
- 5.5 Literal Route Type
- 5.6 Segment Route Type
- 5.7 Regex Route Type
- 5.8 Wildcard Route Type
- 5.9 Other Route Types
-
5.10 Extracting Parameters from Route
- 5.10.1 Retrieving the RouteMatch and the Router Object
-
5.11 Generating URLs from Route
-
5.11.1 Generating URLs in View Templates
- 5.11.1.1 Passing Parameters
- 5.11.1.2 Generating Absolute URLs
- 5.11.1.3 Specifying Query Part
- 5.11.2 Generating URLs in Controllers
- 5.11.3 URL Encoding
-
5.11.1 Generating URLs in View Templates
-
5.12 Writing Own Route Type
- 5.12.1 RouteInterface
- 5.12.2 Custom Route Class
- 5.13 Summary
-
6. Page Appearance and Layout
- 6.1 About CSS Stylesheets and Twitter Bootstrap
- 6.2 Page Layout in Zend Framework 2
- 6.3 Modifying the Default Page Layout
-
6.4 Switching between Layouts
- 6.4.1 Setting Layout for All Actions of a Controller
- 6.5 Partial Views
- 6.6 Placeholder View Helper
-
6.7 Adding Scripts to a Web Page
- 6.7.1 Example
-
6.8 Adding CSS Stylesheets to a Web Page
- 6.8.1 Example
-
6.9 Writing Own View Helpers
- 6.9.1 Menu
- 6.9.2 Breadcrumbs
- 6.10 View Models and Page Composition
- 6.11 Summary
-
7. Collecting User Input with Forms
- 7.1 Get the Form Demo Sample from GitHub
-
7.2 About HTML Forms
- 7.2.1 Fieldsets
- 7.2.2 Example: “Contact Us” Form
- 7.2.3 GET and POST Methods
- 7.3 Styling HTML Forms with Twitter Bootstrap
- 7.4 Retrieving Form Data in a Controller’s Action
-
7.5 Forms and Model-View-Controller
- 7.5.1 A Typical Form Usage Workflow
- 7.6 A Form Model
-
7.7 Form Elements
- 7.7.1 Adding Elements to a Form Model
- 7.7.2 Method 1: Passing an Instance of an Element
- 7.7.3 Method 2: Using Array Specification
- 7.8 Example: Creating the Contact Form Model
-
7.9 Adding Form Validation Rules
- 7.9.1 Input Filter
-
7.9.2 Adding Inputs to Input Filter
- 7.9.2.1 Filter Configuration
- 7.9.2.2 Validator Configuration
- 7.9.2.3 Attaching Input Filter to Form Model
- 7.9.3 Creating Input Filter for the Contact Form
-
7.10 Using the Form in a Controller’s Action
- 7.10.1 Passing Form Data to a Model
-
7.11 Form Presentation
- 7.11.1 Preparing the Form Model for Rendering
-
7.12 Standard Form View Helpers
- 7.12.1 Rendering a Form Element
- 7.12.2 Rendering an Element’s Validation Errors
- 7.12.3 Rendering an Element’s Label
- 7.12.4 Rendering a Form Row
- 7.12.5 Rendering the Entire Form
-
7.13 Example: Creating the View Template for the Contact Form
- 7.13.1 Applying the Bootstrap CSS Styles to Form
- 7.13.2 Styling the Validation Errors List
- 7.13.3 Adding the “Thank You” & “Error Sending Email” Pages
- 7.13.4 Results
- 7.14 Summary
-
8. Transforming Input Data with Filters
-
8.1 About Filters
- 8.1.1 FilterInterface
- 8.2 Standard Filters Overview
-
8.3 Instantiating a Filter
- 8.3.1 Method 1: Instantiating a Filter Manually
- 8.3.2 Method 2: Constructing a Filter with StaticFilter
- 8.3.3 Method 3: Constructing a Filter From Array
- 8.4 About Filter Plugin Manager
- 8.5 Filter’s Behavior in Case of Incorrect Input Data
-
8.6 Filter Usage Examples
-
8.6.1 Filters Casting Input Data to a Specified Type
- 8.6.1.1 Int Filter
- 8.6.1.2 Boolean Filter
- 8.6.1.3 Null Filter
- 8.6.1.4 DateTimeFormatter Filter
-
8.6.2 Filters Performing Manipulations on a File Path
- 8.6.2.1 BaseName Filter
- 8.6.2.2 Dir Filter
- 8.6.2.3 RealPath Filter
-
8.6.3 Filters Performing Compression and Encryption of Input Data
- 8.6.3.1 Compress Filter
- 8.6.3.2 Encrypt Filter
-
8.6.4 Filters Manipulating String Data
- 8.6.4.1 StringToLower Filter
- 8.6.4.2 PregReplace Filter
- 8.6.4.3 StripTags Filter
- 8.6.4.4 StripNewlines Filter
- 8.6.4.5 UriNormalize Filter
- 8.6.5 Organizing Filters in a Chain
-
8.6.6 Custom Filtering with the Callback Filter
- 8.6.6.1 Example
-
8.6.1 Filters Casting Input Data to a Specified Type
-
8.7 Writing Your Own Filter
- 8.7.1 Using the PhoneFilter Class
- 8.8 Summary
-
8.1 About Filters
-
9. Checking Input Data with Validators
-
9.1 About Validators
- 9.1.1 ValidatorInterface
- 9.2 Standard Validators Overview
- 9.3 Validator Behaviour in Case of Invalid or Unacceptable Data
-
9.4 Instantiating a Validator
- 9.4.1 Method 1. Manual Instantiation of a Validator
- 9.4.2 Method 2. Using StaticValidator Wrapper
- 9.4.3 Method 3. Using an Array Configuration
- 9.5 About Validator Plugin Manager
-
9.6 Validator Usage Examples
-
9.6.1 Validators for Checking Value Conformance to Certain Format
- 9.6.1.1 Ip Validator
- 9.6.1.2 Hostname Validator
- 9.6.1.3 Uri Validator
- 9.6.1.4 Date Validator
- 9.6.1.5 Regex Validator
-
9.6.2 Validators for Checking a Numerical Value Lies in a Given Range
- 9.6.2.1 NotEmpty Validator
- 9.6.2.2 Between Validator
- 9.6.2.3 InArray Validator
- 9.6.2.4 StringLength Validator
- 9.6.3 Organizing Validators in a Chain
-
9.6.4 Custom Validation with the Callback Validator
- 9.6.4.1 Example
-
9.6.1 Validators for Checking Value Conformance to Certain Format
-
9.7 Writing Own Validator
- 9.7.1 Using the PhoneValidator Class
- 9.8 Using Filters & Validators Outside a Form
- 9.9 Summary
-
9.1 About Validators
-
10. Uploading Files with Forms
-
10.1 About HTTP File Uploads
- 10.1.1 HTTP Binary Transfer Encoding
- 10.1.2 $_FILES Super-Global Array in PHP
- 10.2 Accessing Uploaded Files in ZF2
- 10.3 File Uploads & ZF2 Form Model
- 10.4 Validating Uploaded Files
- 10.5 Filtering Uploaded Files
-
10.6 InputFilter Container & File Uploads
- 10.6.1 FileInput
- 10.6.2 Executing Validators before Filters
- 10.7 Controller Action & File Uploads
-
10.8 Example: Image Gallery
- 10.8.1 Adding ImageForm Model
- 10.8.2 Adding Validation Rules to ImageForm Model
- 10.8.3 Writing ImageManager Service
-
10.8.4 Adding ImageController
- 10.8.4.1 Adding Upload Action & Corresponding View Template
- 10.8.4.2 Adding Index Action & Corresponding View Template
- 10.8.4.3 Adding File Action
- 10.8.4.4 Registering the ImageController
- 10.8.5 Results
- 10.9 Summary
-
10.1 About HTTP File Uploads
-
11. Advanced Usage of Forms
-
11.1 Form Security Elements
-
11.1.1 CAPTCHA
- 11.1.1.1 CAPTCHA Types
- 11.1.1.2 CAPTCHA Form Element & View Helper
- 11.1.2 Example 1: Adding Image CAPTCHA to the ContactForm
- 11.1.3 Example 2: Adding a FIGlet CAPTCHA to the ContactForm
- 11.1.4 Example 3: Adding reCaptcha CAPTCHA to the ContactForm
-
11.1.5 CSRF Prevention
- 11.1.5.1 Example: Adding a CSRF Element to Form
-
11.1.1 CAPTCHA
- 11.2 Summary
-
11.1 Form Security Elements
-
12. Database Management with Doctrine ORM
- 12.1 Get Blog Example from GitHub
-
12.2 Creating a Simple MySQL Database
- 12.2.1 Creating New Schema
- 12.2.2 Creating Tables
- 12.2.3 Importing Ready Database Schema
-
12.3 Integrating Doctrine ORM with Zend Framework 2
- 12.3.1 Installing Doctrine Components with Composer
- 12.3.2 Loading Doctrine Integration Modules on Application Start Up
- 12.3.3 Doctrine Configuration Overview
- 12.3.4 Overriding the Default Doctrine Configuration
- 12.4 Specifying Database Connection Parameters
-
12.5 About Doctrine Entities
- 12.5.1 Annotations
-
12.6 Creating Entities
- 12.6.1 Adding Post Entity
- 12.6.2 Adding the Comment and Tag Entities
-
12.6.3 Specifying Relations between Entities
- 12.6.3.1 OneToMany/ManyToOne
- 12.6.3.2 ManyToMany
- 12.6.4 Specifying Entity Locations
-
12.7 About Entity Manager
- 12.7.1 Entity Repositories
- 12.8 Adding Blog Home Page
-
12.9 Adding New Post
- 12.9.1 Adding PostForm
- 12.9.2 Adding PostManager Service
- 12.9.3 Creating Controller Action and View Template
-
12.10 Editing Existing Post
- 12.10.1 Modifying PostManager
- 12.10.2 Adding Controller Action and View Template
-
12.11 Deleting Post
- 12.11.1 Modifying PostManager
- 12.11.2 Adding Controller Action
-
12.12 Implementing Post Preview
- 12.12.1 Adding CommentForm
- 12.12.2 Modifying PostManager
- 12.12.3 Adding Controller Action and View Template
- 12.13 Implementing Admin Page
-
12.14 Implementing Tag Cloud
- 12.14.1 Adding Custom Post Repository
- 12.14.2 Calculating Tag Cloud
- 12.14.3 Modifying Controller Action
- 12.14.4 Rendering Tag Cloud
- 12.15 Summary
-
Appendix A. Configuring Web Development Environment
-
Installing Apache, PHP and MySQL in Linux
- Installing Apache and PHP
- Checking Web Server Installation
- Editing PHP Configuration
- Restarting Apache Web Server
- Enabling Apache’s mod_rewrite module
- Creating Apache Virtual Host
- Installing XDebug PHP extension
- Installing APC PHP Extension
- Installing MySQL Database Server
- Configuring the MySQL Database Server
-
Installing Apache, PHP and MySQL in Windows
- Checking Web Server Installation
- Enabling Apache’s mod_rewrite module
- Creating Apache Virtual Host
- Installing XDebug PHP extension
- Installing MySQL Database Server
- Configuring the MySQL Database Server
-
Installing NetBeans IDE in Linux
- Method 1. Installing from Repository
- Method 2. Downloading from Web Site
- Installing NetBeans IDE in Windows
- Summary
-
Installing Apache, PHP and MySQL in Linux
-
Appendix B. Introduction to PHP Development in NetBeans IDE
- Run Configuration
- Running the Web Site
- Site Debugging in NetBeans
- Debug Toolbar
- Breakpoints
- Watching Variables
- Call Stack
- Debugging Options
- Profiling
- Summary
-
Appendix C. Introduction to Twitter Bootstrap
- Overview of Bootstrap Files
-
Grid System
- Defining the Grid
- Offsetting Columns
- Nesting Grids
- “Mobile First” Concept
-
Bootstrap’s Interface Components
-
Navigation Bar
- Dropdown Menu
- Collapsible Navbar
- Inverse Navbar Style
- Breadcrumbs
- Pagination
- Buttons & Glyphicons
-
Navigation Bar
- Customizing Bootstrap
- Summary
-
Appendix D. Introduction to Doctrine
-
Doctrine and Database Management Systems
-
Relational Databases
- SQL vs. DQL
-
NoSQL Databases
- Document Databases
-
Relational Databases
-
Doctrine Architecture
- Components Supporting Relational Databases
- Components Supporting NoSQL Document Databases
- Summary
-
Doctrine and Database Management Systems
- About the Author
Causes Supported

Electronic Frontier Foundation
Defending your civil liberties in a digital world.
https://www.eff.org/Based in San Francisco, EFF is a donor-supported membership organization working to protect fundamental rights regardless of technology.
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,718,542writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Recipes for Decoupling
Matthias NobackWrite software that survives
CQRS by Example
Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary- Leverage your Software Architecture skills by learning everything about CQRS in detail with lots of examples
- Develop faster applications by applying CQRS and fostering Read Models and Projections
- Learn how to apply CQRS into a brownfield project from a pragmatic approach
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
The PowerShell Scripting and Toolmaking Book
Don Jones and Jeff HicksLearn the patterns, practices, and details of PowerShell Scripting and Toolmaking from the industry's two most recognized experts on the subject.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Introduction to Data Science
Rafael A IrizarryThe demand for skilled data science practitioners in industry, academia, and government is rapidly growing. This book introduces concepts from probability, statistical inference, linear regression and machine learning and R programming skills. Throughout the book we demonstrate how these can help you tackle real-world data analysis challenges.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #3
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #5
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #10
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...