photon/storage-mongodb-object

v3.1.0 2017-09-26 16:05 UTC

README

Build Status

Micro ORM for MongoDB

PHP Versions

  • 5.6, 7.0 and 7.1 are supported and tested under travis
  • Use ext-mongodb and mongodb/mongodb. Do not works anymore with legacy ext-mongo

Quick start

  1. Add the module in your project

    composer require "photon/storage-mongodb-object:dev-master"

or for a specific version

composer require "photon/storage-mongodb-object:2.0.0"
  1. Define a MongoDB connection in your project configuration

    'databases' => array( 'default' => array( 'engine' => '\photon\db\MongoDB', 'server' => 'mongodb://localhost:27017/', 'database' => 'orm', 'options' => array( 'connect' => true, ), ), ),

  2. Create custom object in PHP

    class User extends \photon\storage\mongodb\Object { const collectionName = 'users';

     public function initObject()
     {
         $this->ctm = new DateTime;
         $this->activated = false;
     }
    

    }

  3. Use your object

    $user = new User; $user->name = 'Foo'; $user->save();

  4. Enjoy !