售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Zend Framework 2 Cookbook
Table of Contents
Zend Framework 2 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Zend Framework 2 Basics
Introduction
Setting up a Zend Framework 2 project
Getting ready
How to do it…
Cloning the skeleton
Moving the skeleton
Initializing the Composer
How it works…
There's more…
See also
Handling routines
How to do it…
Setting up routing
Using SimpleRouteStack
Using TreeRouteStack
How it works…
There's more…
Namespace – Zend\Mvc\Router\Http
The Hostname class explained
The Literal class explained
Methods explained
The Part class explained
Regex explained
The Scheme class explained
The Segment class explained
Understanding dependency injection
How to do it…
Initializing the DI at call-time
Initializing the DI through a Configuration object
How it works…
The DI only gives out one instance of an object
Defining either all properties, or using a Fully Qualified (FQ) setter parameter
There's more…
Using configurations to your benefit
How to do it…
Creating a global configuration
Creating configuration that only works for a local machine
Editing your application.config.php file
How it works…
There's more…
The EventManager and Bootstrap classes
How to do it…
Using the bootstrap
Starting a session
Using the EventManager class
Changing the View output
How it works…
The Observer pattern explained
Aspect-Oriented Programming (AOP) explained
Event-driven architecture explained
There's more…
2. Translating and Mail Handling
Introduction
Translating your application
Getting ready
How to do it…
Setting up and checking the essentials
Translating strings in the controller
Translating strings in the View
Translating strings with Poedit
How it works…
Basic set up of translation in your module
There's more…
PHP array
Gettext
Ini
Localizing your application
How to do it…
So it begins
Localizing currencies
Localizing date/times
How it works…
Identifying the client language
Localizing currencies and dates
Sending mail
How to do it…
Transport\Sendmail
Transport\Smtp
Transport\File
How it works…
Sending mail through SMTP
Sending mail through files
Receiving mail
Getting ready
How to do it…
Connecting to an IMAP mail server
Connecting to a POP3 mail server
Working with flags on IMAP or Maildir connections
Maildir++ Quota system
Keeping a connection alive
How it works…
Connecting to a POP3 server
About the Maildir++ Quota system
Keeping the connection alive
There's more…
3. Handling and Decorating Forms
Introduction
Creating forms
Getting ready…
How to do it…
Creating a basic form
Defining a form that is extended from Zend\Form
Defining a form that uses the Zend\Form\Annotation
Adding elements to a Zend\Form extend form
Adding elements to an annotated form
Validating form input
How it works…
Setting up a basic form
Setting up an annotated form
Adding elements to the form
Forms, filtering, and validation
There's more…
Using form view helpers
How to do it…
Form
FormButton
FormCaptcha
FormCheckbox
FormCollection
FormColor
FormDate, FormDateTime, and FormDateTimeLocal
FormEmail
FormFile
FormHidden
FormImage
FormInput
FormLabel
FormElementErrors
How it works…
Form
FormButton
FormCaptcha
FormCheckbox
FormCollection
FormColor
FormDate, FormDateTime, and FormDateTimeLocal
FormEmail
FormFile
FormHidden
FormImage
FormInput
FormLabel
FormElementErrors
Creating a custom form element and form view helper
How to do it…
Creating the new element
Creating the new view helper
Adding view helper to the configuration
Displaying the new element
How it works…
Creating the element
What did we do
4. Using View
Introduction
Working with View
Getting ready
How to do it…
Configure the ViewManager
Set variables in the ViewModel instance
Mark up the template file
How it works…
The configuration
The ViewModel instance
The ViewStrategy class
The ViewRenderer helper
Getting ready
How to do it…
The BasePath view helper
The Doctype view helper
The URL view helper
The Partial view helper
How it works…
Zend\View\Helper\AbstractHelper
The BasePath view helper explained
The Doctype view helper explained
The URL view helper explained
The Partial view helper explained
There's more…
Creating a global layout template
Getting ready
How to do it…
Creating the main layout file
Creating the error templates
How it works…
Creating reusable Views
Getting ready
How to do it…
Use the Action view helper to get the re-usable content
Define a child to the ViewModel instance
How it works…
The Action view helper explained
Defining a child to a ViewModel instance explained
Pros and cons
Using view strategies/renderers
Getting ready
How to do it…
Adding a view strategy
The JSON strategy
The Feed strategy
How it works…
The view strategy class
The default view strategies
The JSON strategy explained
The Feed strategy explained
More about view strategies
Using context switching for a different output
Getting ready
How to do it…
Define multiple strategies to output
Determine the view model based on the Accept header
How it works…
There's more…
Writing a custom view strategy/renderer
How to do it…
Creating the XmlOutput renderer
How it works…
The XmlRenderer and XmlModel
The XmlStrategy
There's more…
5. Configuring and Using Databases
Introduction
Default database engines available
IBM DB2 driver
MySQLi driver
OCI8 driver
PGSQL driver
SQLSRV driver
PDO driver
Connecting to a database
Getting ready
How to do it…
Connecting to a MySQL database through the configuration
Connecting to multiple databases through the configuration
Connecting to a MySQL database through code
How it works…
Connecting to a MySQL database through the configuration
Connecting to multiple databases through the configuration
About the ServiceManager
Executing simple queries
Getting ready
How to do it…
Using raw SQL
Using the prepared statements
Quote identifier
Quote identifier chain
Quote (trusted) value
Quote value list
Quote identifier in fragment
How it works…
Using raw SQL
Using prepared statements
Quoting in our SQL
Using createStatement
Executing queries using TableGateway
Getting ready
How to do it…
Inserting a new record
Updating a record
Deleting a record
Advanced selects – joins conditions
How it works…
Optimizating with a DB profiler
Getting ready
How to do it…
Setting up a new profiler
How it works…
There's more…
Creating a Database Access Object
Getting ready
How to do it…
Creating our new module and configuration
Creating a connector
Creating a mapper interface
Creating an abstract mapper class
Creating a Data Transfer Object
Creating a mapper class
How it works…
About the DAO
About the recipe
6. Modules, Models, and Services
Introduction
Creating a new module
Getting ready
How to do it…
Creating the Module.php
Attaching to the loadModules.postevent
Implementing the getAutoloaderConfig
Implementing the getControllerConfig, getControllerPluginConfig and getViewHelperConfig
How it works…
Creating a new module directory
Creating the Module.php
Optionally act on ModuleManager events
Understanding the loadModules event
The loadModules.resolve event
The loadModule event
The loadModules.post
Attaching to the loadModules.post event
More specific non configuration file Module configuration
The getAutoloaderConfig method
The getControllerConfig, getControllerPluginConfig, and getViewHelperConfig methods
Using modules as a widget
Getting ready
How to do it…
Creating the Comment/Controller/Index
Using a view helper to display the comments statically
Using the forward to render the comments statically
Getting the comments through AJAX
How it works…
Using a view helper to display the comments statically
Using the forward() method to render the comments statically
Getting the comments through AJAX
About Widgetizing
A Model and a Hydrator
Getting ready
How to do it…
Accessing the Model
Creating a Hydrator
Creating a Hydrator strategy
How it works…
Think about the model's purpose
Think about the model's location
Think about the model's methods
Unit test the model
Document your class
Creating a hydrator
Creating a hydrator strategy
About models
There's more…
A basic service
Getting ready
How to do it…
Creating a service
Getting a service from within a controller
How it works…
7. Handling Authentication
Introduction
Understanding Authentication methods
Getting ready
How to do it…
The DbTable adapter
The Http adapter
How it works…
The DbTable adapter (again)
The Http adapter (again)
The Digest adapter
The LDAP adapter
About Authentication
Setting up a simple database Authentication
Getting ready
How to do it…
Setting up the module initialization
Creating the authentication service
Setting up the controller and action
How it works…
Writing a custom Authentication method
Getting ready
How to do it…
Creating our adapter
The adapter outline
Creating a getter and setter for any error messages
Making sure we have a secure connection
Checking if the certificate is an actual certificate
Checking if we have all the certificate fields
Checking if the certificate isn't expired yet
Creating a getter and setter for the Database adapter
Creating the authenticate method
How it works…
What are we trying to achieve
About certificates
There's more…
8. Optimizing Performance
Introduction
Caching and when to Cache
Getting ready
How to do it…
Caching configuration
Caching output
Caching the class map
How it works…
Understanding and using storage plugins
How to do it…
Using the ClearExpiredByFactor plugin
Using the ExceptionHandler plugin
Using the IgnoreUserAbort plugin
Using the OptimizeByFactor plugin
Using the Serializer plugin
Using any plugin
How it works…
Setting up a caching system
Getting ready
How to do it…
Benchmarking our application before cache
Implementing configuration/class map cache
Implementing the class caching
How it works…
9. Catching Bugs
Introduction
Handling Exceptions – your partner in crime
Getting ready
How to do it...
Exception classes in Zend Framework 2
Handling Exceptions on dispatch or rendering
How it works...
Exception classes in Zend Framework 2
Handling exceptions on dispatch or rendering
About try-catch
See also
Logging and how it makes your life easier
Getting ready
How to do it...
Implementing a really simple file logger
Implementing a FirePHP logger
How it works...
Implementing a really simple file logger
Implementing a FirePHP logger
About the Logger
Unit testing – why would you do it
Getting ready
How to do it...
Pseudo-code examples
How it works...
What is unit testing
When should we test? – before, or after code is written
It is a matter of discipline
Setting up and using unit testing
Getting ready
How to do it...
Setting up the test framework
How it works...
There's more...
See also
A. Setting up the Essentials
Making sure you have all that you need
Installing Zend Server Community Edition on a Linux environment
Installing Zend Server Community Edition on a Windows environment
First-time run of Zend Server
See also
Downloading Zend Framework 2 and finding its documentation
Finding Zend Framework 2
Coding in the phpcloud
The documentation and getting started guide
See also
Composer and its uses within Zend Framework 2
The composer.json file
Upgrading packages
See also
Basic Zend Framework 2 structures
Folder – config
Folder – module
Folder – public
Folder – vendor
File – init_autoloader.php
What's next?
About storage adapters and patterns
Storage adapter's implementations
Storage adapters
Apc caching
Dba caching
File system caching
Memcached caching
Memory caching
Redis caching
Session caching
WinCache caching
XCache caching
ZendServerDisk caching
ZendServerShm caching
Cache patterns
The CallbackCache pattern
The CaptureCache pattern
The ClassCache pattern
The ObjectCache pattern
The OutputCache pattern
The PatternOptions pattern
Explaining the difference
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜