Zend session initiation

。_饼干妹妹 提交于 2019-12-24 12:22:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!