问题
I have the following code in my zend application bootstrap file
protected function _initSessionId() {
$this->bootstrap( 'session' );
$opts = $this->getOptions();
$cache = $this->bootstrap( 'cachemanager' )
->getResource( 'cachemanager' )
->getCache( 'memcached' );
Zend_Db_Table_Abstract::setDefaultMetadataCache( $cache );
Zend_Registry::set( 'cache', $cache );
$defaultNamespace = new Zend_Session_Namespace();
if ( !isset( $defaultNamespace->initialized ) ) {
Zend_Session::regenerateId();
$defaultNamespace->initialized = true;
}
}
I want to know what the line $this->bootstrap('session')
actually does. Which class/function does it instantiate and call?
回答1:
How to bootstrap a resource
bootstrap(<resource_name>)
tells to Zend_Bootstrap to init the specified resource before continue. Usually is used for init required dependencies before init the actual resource
The resource bootstrap can be declared in two ways.
A PHP method in the Bootstrap
class.
function _init<Resource_name>() { ... }
Or in the ini
file
resources.<resource_name>
in the last case (ini
file) a class extending from Zend_Application_Resource_ResourceAbstract
must be declared with the code for init the resource.
Session resource bootstrap
For the concrete case of bootstrap('session')
by default use the init()
method declared in Zend_Application_Resource_Session
来源:https://stackoverflow.com/questions/15902528/zend-session-initiation