douping3891 2012-02-17 17:49
浏览 35

CakePHP 2.0.2上的自定义会话处理程序

i tried follow from http://book.cakephp.org/2.0/en/development/sessions.html#creating-a-custom-session-handler then i cant solve this and im really confuse about this :(

become like this:

<?php
App::uses('DatabaseSession', 'Model/Datasource/Session');

class CartSession implements CakeSessionHandlerInterface {
    public $cacheKey;

    public function __construct() {
        $this->cacheKey = Configure::read('Session.handler.cache');
        parent::__construct();
    }

    // read data from the session.
    public function read($id) {
        $result = Cache::read($id, $this->cacheKey);
        if ($result) {
            return $result;
        }
        return parent::read($id);
    }

    // write data into the session.
    public function write($id, $data) {
        $result = Cache::write($id, $data, $this->cacheKey);
        if ($result) {
            return parent::write($id, $data);
        }
        return false;
    }

    // destroy a session.
    public function destroy($id) {
        $result = Cache::delete($id, $this->cacheKey);
        if ($result) {
            return parent::destroy($id);
        }
        return false;
    }

    // removes expired sessions.
    public function gc($expires = null) {
        return Cache::gc($this->cacheKey) && parent::gc($expires);
    }
}

?>

Output Error:

Fatal error: Class CartSession contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (CakeSessionHandlerInterface::open, CakeSessionHandlerInterface::close) in /Users/user/Sites/app/shop/Model/Datasource/Session/CartSession.php on line 43

I did added in core.php:

Configure::write('Session', array(
        'defaults' => 'database',
        'handler' => array(
            'engine' => 'CartSession',
            'model' => 'Session',
            'cache' => 'apc'
        )
    ));

 Cache::config('apc', array('Engine' => 'Apc'));
  • 写回答

1条回答 默认 最新

  • doxn43207 2012-08-23 18:17
    关注

    You need to extend DatabaseSession. So your class declaration will look like:

    class CartSession extends DatabaseSession implements CakeSessionHandlerInterface

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大