Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /_sources/modules/zend.session.save-handler.mongo-db.txt

Size:786
Storage flags:no_autoload,compress/gzip (45%)

:orphan:

.. _zend.session.save-handler.mongodb:

MongoDB
-------

``Zend\Session\SaveHandler\MongoDB`` allows you to provide a MongoDB instance to be utilized as a session
save handler.  You provide the options in the ``Zend\Session\SaveHandler\MongoDBOptions`` class.

Basic Usage
^^^^^^^^^^^

A basic example is one like the following:

.. code-block:: php
   :linenos:

   use Mongo;
   use Zend\Session\SaveHandler\MongoDB;
   use Zend\Session\SaveHandler\MongoDBOptions;
   use Zend\Session\SessionManager;

   $mongo = new Mongo();
   $options = new MongoDBOptions(array(
       'database'   => 'myapp',
       'collection' => 'sessions',
   ));
   $saveHandler = new MongoDB($mongo, $options);
   $manager     = new SessionManager();
   $manager->setSaveHandler($saveHandler);


For more information about the PHK package format: http://phk.tekwire.net