Previous Next

Core Functionality

Here you'll find API-like documentation about all core components of Zend_Application.

Zend_Application

Zend_Application provides the base functionality of the component, and the entry point to your Zend Framework application. It's purpose is two-fold: to setup the PHP environment (including autoloading), and to execute your application bootstrap.

Typically, you will pass all configuration to the Zend_Application constructor, but you can also configure the object entirely using its own methods. This reference is intended to illustrate both use cases.

Zend_Application options
Option Description
phpSettings

Array of php.ini settings to use. Keys should be the php.ini keys.

includePaths

Additional paths to prepend to the include_path. Should be an array of paths.

autoloaderNamespaces

Array of additional namespaces to register with the Zend_Loader_Autoloader instance.

bootstrap

Either the string path to the bootstrap class, or an array with elements for the 'path' and 'class' for the application bootstrap.

Note: Option names

Please note that option names are case insensitive.

Zend_Application Methods
Method Return Value Parameters Description
__construct($environment, $options = null) Void
  • $environment: required,. String representing the current application environment. Typical strings might include "development", "testing", "qa", or "production", but will be defined by your organizational requirements.

  • $options: optional. Argument may be one of the following values:

    • String: path to a Zend_Config file to load as configuration for your application. $environment will be used to determine what section of the configuration to pull.

    • Array: associative array of configuration data for your application.

    • Zend_Config: configuration object instance.

Constructor. Arguments are as described, and will be used to set initial object state. An instance of Zend_Loader_Autoloader is registered during instantiation. Options passed to the constructor are passed to setOptions().

getEnvironment() String N/A

Retrieve the environment string passed to the constructor.

getAutoloader() Zend_Loader_Autoloader N/A

Retrieve the Zend_Loader_Autoloader instance registered during instantiation.

setOptions(array $options) Zend_Application
  • $options: required. An array of application options.

All options are stored internally, and calling the method multiple times will merge options. Options matching the various setter methods will be passed to those methods. As an example, the option "phpSettings" will then be passed to setPhpSettings(). (Option names are case insensitive.)

getOptions() Array N/A

Retrieve all options used to initialize the object; could be used to cache Zend_Config options to a serialized format between requests.

hasOption($key) Boolean
  • $key: String option key to lookup

Determine whether or not an option with the specified key has been registered. Keys are case insensitive.

getOption($key) Mixed
  • $key: String option key to lookup

Retrieve the option value of a given key. Returns NULL if the key does not exist.

setPhpSettings(array $settings, $prefix = '') Zend_Application
  • $settings: required. Associative array of PHP INI settings.

  • $prefix: optional. String prefix with which to prepend option keys. Used internally to allow mapping nested arrays to dot-separated php.ini keys. In normal usage, this argument should never be passed by a user.

Set run-time php.ini settings. Dot-separated settings may be nested hierarchically (which may occur with INI Zend_Config files) via an array-of-arrays, and will still resolve correctly.

setAutoloaderNamespaces(array $namespaces) Zend_Application
  • $namespaces: required. Array of strings representing the namespaces to register with the Zend_Loader_Autoloader instance.

Register namespaces with the Zend_Loader_Autoloader instance.

setBootstrap($path, $class = null) Zend_Application
  • $path: required. May be either a Zend_Application_Bootstrap_Bootstrapper instance, a string path to the bootstrap class, an associative array of classname => filename, or an associative array with the keys 'class' and 'path'.

  • $class: optional. If $path is a string, $class may be specified, and should be a string class name of the class contained in the file represented by path.

getBootstrap() NULL | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

bootstrap() Void N/A

Call the bootstrap's bootstrap() method to bootstrap the application.

run() Void N/A

Call the bootstrap's run() method to dispatch the application.

Zend_Application_Bootstrap_Bootstrapper

Zend_Application_Bootstrap_Bootstrapper is the base interface all bootstrap classes must implement. The base functionality is aimed at configuration, identifying resources, bootstrapping (either individual resources or the entire application), and dispatching the application.

The following methods make up the definition of the interface.

Zend_Application_Bootstrap_Bootstrapper Interface
Method Return Value Parameters Description
__construct($application) Void
  • $application: required. Should accept a Zend_Application or a Zend_Application_Bootstrap_Bootstrapper object as the sole argument.

Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object.

setOptions(array $options) Zend_Application_Bootstrap_Bootstrapper
  • $options: required. Array of options to set.

Typically, any option that has a matching setter will invoke that setter; otherwise, the option will simply be stored for later retrieval.

getApplication() Zend_Application | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the application or bootstrap object passed via the constructor.

getEnvironment() String N/A

Retrieve the environment string registered with the parent application or bootstrap object.

getClassResources() Array N/A

Retrieve a list of available resource initializer names as defined in the class. This may be implementation specific.

bootstrap($resource = null) Mixed
  • $resource: optional.

If $resource is empty, execute all bootstrap resources. If a string, execute that single resource; if an array, execute each resource in the array.

run() Void N/A

Defines what application logic to run after bootstrapping.

Zend_Application_Bootstrap_ResourceBootstrapper

Zend_Application_Bootstrap_ResourceBootstrapper is an interface to use when a bootstrap class will be loading external resources -- i.e., one or more resources will not be defined directly in the class, but rather via plugins. It should be used in conjunction with Zend_Application_Bootstrap_Bootstrapper; Zend_Application_Bootstrap_BootstrapAbstract implements this functionality.

The following methods make up the definition of the interface.

Zend_Application_Bootstrap_ResourceBootstrapper Interface
Method Return Value Parameters Description
registerPluginResource($resource, $options = null) Zend_Application_Bootstrap_ResourceBootstrapper
  • $resource: required. A resource name or Zend_Application_Resource_Resource object.

  • $options: optional. An array or Zend_Config object to pass to the resource on instantiation.

Register a resource with the class, providing optional configuration to pass to the resource.

unregisterPluginResource($resource) Zend_Application_Bootstrap_ResourceBootstrapper
  • $resource: required. Name of a resource to unregister from the class.

Remove a plugin resource from the class.

hasPluginResource($resource) Boolean
  • $resource: required. Name of the resource.

Determine if a specific resource has been registered with the class.

getPluginResource($resource) Zend_Application_Resource_Resource
  • $resource: required. Name of a resource to retrieve (string).

Retrieve a plugin resource instance by name.

getPluginResourceNames() Array N/A

Retrieve a list of all registered plugin resource names.

setPluginLoader(Zend_Loader_PluginLoader_Interface $loader) Zend_Application_Bootstrap_ResourceBootstrapper
  • $loader: required. Plugin loader instance to use when resolving plugin names to classes.

Register a plugin loader instance to use when resolving plugin class names.

getPluginLoader() Zend_Loader_PluginLoader_Interface N/A

Retrieve the registered plugin loader.

Zend_Application_Bootstrap_BootstrapAbstract

Zend_Application_Bootstrap_BootstrapAbstract is an abstract class which provides the base functionality of a common bootstrap. It implements both Zend_Application_Bootstrap_Bootstrapper and Zend_Application_Bootstrap_ResourceBootstrapper.

Zend_Application_Bootstrap_BootstrapAbstract Methods
Method Return Value Parameters Description
__construct($application) Void
  • $application: required. Accepts either a Zend_Application or a Zend_Application_Bootstrap_Bootstrapper object as the sole argument.

Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object.

setOptions(array $options) Zend_Application_Bootstrap_Bootstrapper
  • $options: required. Array of options to set.

Any option that has a matching setter will invoke that setter; otherwise, the option will simply be stored for later retrieval. As an example, if your extending class defined a setFoo() method, the option 'foo' would pass the value to that method.

Two additional, special options keys may also be used. pluginPaths may be used to specify prefix paths to plugin resources; it should be an array of class prefix to filesystem path pairs. resources may be used to specify plugin resources to use, and should consist of plugin resource to instantiation options pairs.

getOption() Array N/A

Returns all options registered via setOptions().

hasOption($key) Boolean
  • $key: required. Option key to test.

Determine if an option key is present.

getOption($key) Mixed
  • $key: required. Option key to retrieve.

Retrieve the value associated with an option key; returns NULL if no option is registered with that key.

setApplication(Zend_Application | Zend_Application_Bootstrap_Bootstrapper $application) Zend_Application_Bootstrap_BootstrapAbstract
  • $application: required.

Register the parent application or bootstrap object.

getApplication() Zend_Application | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the application or bootstrap object passed via the constructor.

getEnvironment() String N/A

Retrieve the environment string registered with the parent application or bootstrap object.

getClassResources() Array N/A

Retrieve a list of available resource initializer names as defined in the class. This may be implementation specific.

getContainer() Object N/A

Retrieves the container that stores resources. If no container is currently registered, it registers a Zend_Registry instance before returning it.

setContainer($container) Zend_Application_Bootstrap_BootstrapAbstract
  • $container, required. An object in which to store resources.

Provide a container in which to store resources. When a resource method or plugin returns a value, it will be stored in this container for later retrieval.

hasResource($name) Boolean
  • $name, required. Name of a resource to check.

When a resource method or plugin returns a value, it will be stored in the resource container (see getContainer() and setContainer(). This method will indicate whether or not a value for that resource has been set.

getResource($name) Mixed
  • $name, required. Name of a resource to fetch.

When a resource method or plugin returns a value, it will be stored in the resource container (see getContainer() and setContainer(). This method will retrieve a resources from the container.

bootstrap($resource = null) Mixed
  • $resource: optional.

If $resource is empty, execute all bootstrap resources. If a string, execute that single resource; if an array, execute each resource in the array.

This method can be used to run individual bootstraps either defined in the class itself or via resource plugin classes. A resource defined in the class will be run in preference over a resource plugin in the case of naming conflicts.

run() Void N/A

Defines what application logic to run after bootstrapping.

__call($method, $args) Mixed
  • $method: required. The method name to call.

  • $args: required. Array of arguments to use in the method call.

Provides convenience to bootstrapping individual resources by allowing you to call 'bootstrap<ResourceName>()' instead of using the bootstrap() method.

Zend_Application_Bootstrap_Bootstrap

Zend_Application_Bootstrap_Bootstrap is a concrete implementation of Zend_Application_Bootstrap_BootstrapAbstract. It's primary feature are that it registers the Front Controller resource, and that the run() method first checks that a default module is defined and then dispatches the front controller.

In most cases, you will want to extend this class for your bootstrapping needs, or simply use this class and provide a list of resource plugins to utilize.

Zend_Application_Resource_Resource

Zend_Application_Resource_Resource is an interface for plugin resources used with bootstrap classes implementing Zend_Application_Bootstrap_ResourceBootstrapper. Resource plugins are expected to allow configuration, be bootstrap aware, and implement a strategy pattern for initializing the resource.

Zend_Application_Resource_Resource Interface
Method Return Value Parameters Description
__construct($options = null) Void
  • $options: optional. Options with which to set resource state.

The constructor should allow passing options with which to initialize state.

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_Resource
  • $bootstrap: required. Parent bootstrap initializing this resource.

Should allow registering the parent bootstrap object.

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

setOptions(array $options) Zend_Application_Resource_Resource
  • $options: required. Options with which to set state.

Set resource state.

getOptions() Array N/A

Retrieve registered options.

init() Mixed N/A

Strategy pattern: run initialization of the resource.

Zend_Application_Resource_ResourceAbstract

Zend_Application_Resource_ResourceAbstract is an abstract class implementing Zend_Application_Resource_Resource, and is a good starting point for creating your own custom plugin resources.

Note: this abstract class does not implement the init() method; this is left for definition in concrete extensions of the class.

Zend_Application_Resource_ResourceAbstract Methods
Method Return Value Parameters Description
__construct($options = null) Void
  • $options: optional. Options with which to set resource state.

The constructor should allow passing options with which to initialize state.

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_ResourceAbstract
  • $bootstrap: required. Parent bootstrap initializing this resource.

Should allow registering the parent bootstrap object.

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

setOptions(array $options) Zend_Application_Resource_ResourceAbstract
  • $options: required. Options with which to set state.

Set resource state.

getOptions() Array N/A

Retrieve registered options.

Resource Names

When registering plugin resources, one issue that arises is how you should refer to them from the parent bootstrap class. There are three different mechanisms that may be used, depending on how you have configured the bootstrap and its plugin resources.

First, if your plugins are defined within a defined prefix path, you may refer to them simply by their "short name" -- i.e., the portion of the class name following the class prefix. As an example, the class "Zend_Application_Resource_View" may be referenced as simply "View", as the prefix path "Zend_Application_Resource" is already registered. You may register them using the full class name or the short name:

$app = new Zend_Application(APPLICATION_ENV, array(
    'pluginPaths' => array(
        'My_Resource' => 'My/Resource/',
    ),
    'resources' => array(
        // if the following class exists:
        'My_Resource_View' => array(),

        // then this is equivalent:
        'View' => array(),
    ),
));

In each case, you can then bootstrap the resource and retrieve it later using the short name:

$bootstrap->bootstrap('view');
$view = $bootstrap->getResource('view');

Second, if no matching plugin path is defined, you may still pass a resource by the full class name. In this case, you can reference it using the resource's full class name:

$app = new Zend_Application(APPLICATION_ENV, array(
    'resources' => array(
        // This will load the standard 'View' resource:
        'View' => array(),

        // While this loads a resource with a specific class name:
        'My_Resource_View' => array(),
    ),
));

Obviously, this makes referencing the resource much more verbose:

$bootstrap->bootstrap('My_Resource_View');
$view = $bootstrap->getResource('My_Resource_View');

This brings us to the third option. You can specify an explicit name that a given resource class will register as. This can be done by adding a public $_explicitType property to the resource plugin class, with a string value; that value will then be used whenever you wish to reference the plugin resource via the bootstrap. As an example, let's define our own view class:

class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    public $_explicitType = 'My_View';

    public function init()
    {
        // do some initialization...
    }
}

We can then bootstrap that resource or retrieve it by the name "My_View":

$bootstrap->bootstrap('My_View');
$view = $bootstrap->getResource('My_View');

Using these various naming approaches, you can override existing resources, add your own, mix multiple resources to achieve complex initialization, and more.

Previous Next
Introduction to Zend Framework
Overview
Installation
Zend_Acl
Introduction
Refining Access Controls
Advanced Usage
Zend_Amf
Introduction
Zend_Amf_Server
Zend_Application
Introduction
Zend_Application Quick Start
Theory of Operation
Examples
Core Functionality
Available Resource Plugins
Zend_Auth
Introduction
Database Table Authentication
Digest Authentication
HTTP Authentication Adapter
LDAP Authentication
Open ID Authentication
Zend_Cache
Introduction
The Theory of Caching
Zend_Cache Frontends
Zend_Cache Backends
Zend_Captcha
Introduction
Captcha Operation
CAPTCHA Adapters
Zend_CodeGenerator
Introduction
Zend_CodeGenerator Examples
Zend_CodeGenerator Reference
Zend_Config
Introduction
Theory of Operation
Zend_Config_Ini
Zend_Config_Xml
Zend_Config_Writer
Zend_Config_Writer
Zend_Console_Getopt
Introduction
Declaring Getopt Rules
Fetching Options and Arguments
Configuring Zend_Console_Getopt
Zend_Controller
Zend_Controller Quick Start
Zend_Controller Basics
The Front Controller
The Request Object
The Standard Router
The Dispatcher
Action Controllers
Action Helpers
The Response Object
Plugins
Using a Conventional Modular Directory Structure
MVC Exceptions
Migrating from Previous Versions
Zend_Currency
Introduction to Zend_Currency
How to Work with Currencies
Migrating from Previous Versions
Zend_Date
Introduction
Theory of Operation
Basic Methods
Zend_Date API Overview
Creation of Dates
Constants for General Date Functions
Working Examples
Zend_Db
Zend_Db_Adapter
Zend_Db_Statement
Zend_Db_Profiler
Zend_Db_Select
Zend_Db_Table
Zend_Db_Table_Row
Zend_Db_Table_Rowset
Zend_Db_Table Relationships
Zend_Db_Table_Definition
Zend_Debug
Dumping Variables
Zend_Dojo
Introduction
Zend_Dojo_Data: dojo.data Envelopes
Dojo View Helpers
Dojo Form Elements and Decorators
Zend_Dojo build layer support
Zend_Dom
Introduction
Zend_Dom_Query
Zend_Exception
Using Exceptions
Zend_Feed
Introduction
Importing Feeds
Retrieving Feeds from Web Pages
Consuming an RSS Feed
Consuming an Atom Feed
Consuming a Single Atom Entry
Modifying Feed and Entry structures
Custom Feed and Entry Classes
Zend_Feed_Reader
Zend_File
Zend_File_Transfer
Validators for Zend_File_Transfer
Filters for Zend_File_Transfer
Migrating from previous versions
Zend_Filter
Introduction
Standard Filter Classes
Filter Chains
Writing Filters
Zend_Filter_Input
Zend_Filter_Inflector
Migrating from Previous Versions
Zend_Form
Zend_Form
Zend_Form Quick Start
Creating Form Elements Using Zend_Form_Element
Creating Forms Using Zend_Form
Creating Custom Form Markup Using Zend_Form_Decorator
Standard Form Elements Shipped With Zend Framework
Standard Form Decorators Shipped With Zend Framework
Internationalization of Zend_Form
Advanced Zend_Form Usage
Zend_Gdata
Introduction
Authenticating with AuthSub
Using the Book Search Data API
Authenticating with ClientLogin
Using Google Calendar
Using Google Documents List Data API
Using Google Health
Using Google Spreadsheets
Using Google Apps Provisioning
Using Google Base
Using Picasa Web Albums
Using the YouTube Data API
Catching Gdata Exceptions
Zend_Http
Introduction
Zend_Http_Client - Advanced Usage
Zend_Http_Client - Connection Adapters
Migrating from previous versions
Zend_Http_Cookie and Zend_Http_CookieJar
Zend_Http_Response
Zend_InfoCard
Introduction
Zend_Json
Introduction
Basic Usage
Advanced Usage of Zend_Json
XML to JSON conversion
Zend_Json_Server - JSON-RPC server
Zend_Layout
Introduction
Zend_Layout Quick Start
Zend_Layout Configuration Options
Zend_Layout Advanced Usage
Zend_Ldap
Introduction
API overview
Usage Scenarios
Tools
Object oriented access to the LDAP tree using Zend_Ldap_Node
Getting information from the LDAP server
Serializing LDAP data to and from LDIF
Zend_Loader
Loading Files and Classes Dynamically
The Autoloader
Resource Autoloaders
Loading Plugins
Zend_Locale
Introduction
Using Zend_Locale
Normalization and Localization
Working with Dates and Times
Supported locales
Migrating from previous versions
Zend_Log
Overview
Writers
Formatters
Filters
Zend_Mail
Introduction
Sending via SMTP
Sending Multiple Mails per SMTP Connection
Using Different Transports
HTML E-Mail
Attachments
Adding Recipients
Controlling the MIME Boundary
Additional Headers
Character Sets
Encoding
SMTP Authentication
Securing SMTP Transport
Reading Mail Messages
Zend_Measure
Introduction
Creation of Measurements
Outputting measurements
Manipulating Measurements
Types of measurements
Zend_Memory
Overview
Memory Manager
Memory Objects
Zend_Mime
Zend_Mime
Zend_Mime_Message
Zend_Mime_Part
Zend_Navigation
Introduction
Pages
Containers
Migrating from Previous Versions
Zend_OpenId
Introduction
Zend_OpenId_Consumer Basics
Zend_OpenId_Provider
Zend_Paginator
Introduction
Usage
Configuration
Advanced usage
Zend_Pdf
Introduction
Creating and Loading PDF Documents
Save Changes to PDF Documents
Working with Pages
Drawing
Interactive Features
Document Info and Metadata
Zend_Pdf module usage example
Zend_ProgressBar
Zend_ProgressBar
Zend_Queue
Introduction
Example usage
Framework
Adapters
Customizing Zend_Queue
Stomp
Zend_Reflection
Introduction
Zend_Reflection Examples
Zend_Reflection Reference
Zend_Registry
Using the Registry
Zend_Rest
Introduction
Zend_Rest_Client
Zend_Rest_Server
Zend_Search_Lucene
Overview
Building Indexes
Searching an Index
Query Language
Query Construction API
Character Set
Extensibility
Interoperating with Java Lucene
Advanced
Best Practices
Zend_Server
Introduction
Zend_Server_Reflection
Zend_Service
Introduction
Zend_Service_Akismet
Zend_Service_Amazon
Zend_Service_Amazon_Ec2
Zend_Service_Amazon_Ec2: Instances
Zend_Service_Amazon_Ec2: Windows Instances
Zend_Service_Amazon_Ec2: Reserved Instances
Zend_Service_Amazon_Ec2: CloudWatch Monitoring
Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)
Zend_Service_Amazon_Ec2: Elastic Block Stroage (EBS)
Zend_Service_Amazon_Ec2: Elastic IP Addresses
Zend_Service_Amazon_Ec2: Keypairs
Zend_Service_Amazon_Ec2: Regions and Availability Zones
Zend_Service_Amazon_Ec2: Security Groups
Zend_Service_Amazon_S3
Zend_Service_Amazon_Sqs
Zend_Service_Audioscrobbler
Zend_Service_Delicious
Zend_Service_Flickr
Zend_Service_Nirvanix
Zend_Service_ReCaptcha
Zend_Service_Simpy
Introduction
Zend_Service_StrikeIron
Zend_Service_StrikeIron: Bundled Services
Zend_Service_StrikeIron: Advanced Uses
Zend_Service_Technorati
Zend_Service_Twitter
Zend_Service_Yahoo
Zend_Session
Introduction
Basic Usage
Advanced Usage
Global Session Management
Zend_Session_SaveHandler_DbTable
Zend_Soap
Zend_Soap_Server
Zend_Soap_Client
WSDL Accessor
AutoDiscovery
Zend_Tag
Introduction
Zend_Tag_Cloud
Zend_Test
Introduction
Zend_Test_PHPUnit
Zend_Test_PHPUnit_Db
Zend_Text
Zend_Text_Figlet
Zend_Text_Table
Zend_TimeSync
Introduction
Working with Zend_TimeSync
Zend_Tool_Framework
Introduction
Using the CLI Tool
Architecture
Creating Providers to use with Zend_Tool_Framework
Shipped System Providers
Extending and Configuring Zend_Tool_Framework
Zend_Tool_Project
Introduction
Create A Project
Zend Tool Project Providers
Zend_Translate
Introduction
Adapters for Zend_Translate
Using Translation Adapters
Creating source files
Additional features for translation
Plural notations for Translation
Migrating from previous versions
Zend_Uri
Zend_Uri
Zend_Validate
Introduction
Standard Validation Classes
Validator Chains
Writing Validators
Validation Messages
Zend_Version
Getting the Zend Framework Version
Zend_View
Introduction
Controller Scripts
View Scripts
View Helpers
Zend_View_Abstract
Migrating from Previous Versions
Zend_Wildfire
Zend_Wildfire
Zend_XmlRpc
Introduction
Zend_XmlRpc_Client
Zend_XmlRpc_Server
Zend Framework Requirements
Introduction
Zend Framework Coding Standard for PHP
Overview
PHP File Formatting
Naming Conventions
Coding Style
Zend Framework Documentation Standard
Overview
Documentation File Formatting
Recommendations
Recommended Project Structure for Zend Framework MVC Applications
Overview
Recommended Project Directory Structure
Module Structure
Rewrite Configuration Guide
Zend Framework Performance Guide
Introduction
Class Loading
Zend_Db Performance
Internationalization (i18n) and Localization (l10n)
View Rendering
Copyright Information