문제

장바구니 작업 중입니다 (장바구니 모델). 보호 된 속성 중 하나는 Product 개체의 배열을 보유하는 "_items"입니다. 그들 (제품)은 모두 세션을 채우기 위해 DB에 저장됩니다 (ZF, Zend_Session_SaveHandler_DbTable () 등 사용). 라코 디스

컨트롤러에서 ProductMapper를 사용하여 DB에서 Product obj를 가져와 "addItem ()"에 제공합니다. 라코 디스

getProductByName()는 새로 채워진 Model_Product 개체를 반환합니다. <시간>

일반적으로

Please ensure that the class definition "Model_Product" of the object you are trying to operate on was loaded _before_ ...

오류 메시지, 세션 덤프에 분명히 표시됨

['__PHP_Incomplete_Class_Name'] => 'Model_Product' <시간>

"직렬화하기 전에 클래스 선언"에 대해 알고 있습니다. 내 문제는 이것이다 : 처음에 주입 된 경우 (첫 번째 매개 변수) addItem()에서 Product 클래스를 어떻게 선언 할 수 있습니까? new Model_Product()와 같은 새로운 선언이 addItem()의 param (원래 객체)을 덮어 쓰지 않습니까? 장바구니 모델에서 다시 신고해야하나요?

게다가 ... 장바구니에서 다시 선언하면 반드시 유전자 코드 코드를 받게됩니다.

도움이 되었습니까?

해결책

In ZF's bootstrap, the session was started before autoloading.

    /**
     * Make XXX_* classes available
     */
    protected function _initAutoloaders()
    {
        $loader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'XXX',
                    'basePath' => APPLICATION_PATH
                ));
    }

    public function _initSession()
    {
        $config = $this->_config->custom->session;

        /**
         * For other settings, see the link below:
         * http://framework.zend.com/manual/en/zend.session.global_session_management.html
         */
        $sessionOptions = array(
            'name'             => $config->name,
            'gc_maxlifetime'   => $config->ttl,
            'use_only_cookies' => $config->onlyCookies,
//            'strict'           => true,
//            'path'             => '/',
        );

        // store session info in DB
        $sessDbConfig = array(
            'name'           => 'xxx_session',
            'primary'        => 'id',
            'modifiedColumn' => 'modified',
            'dataColumn'     => 'data',
            'lifetimeColumn' => 'lifetime'
        );

        Zend_Session::setOptions($sessionOptions);
        Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sessDbConfig));
        Zend_Session::start();
    }

When I was getting the errors I was talking about, the method declaration was the other way around: _initSession() was first, then _initAutoloaders() - and this was the exact order ZF was processing them.

I'll test some more, but this seems to work (and logical). Thanks for all your suggestions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top