2017 © Pedro Peláez
 

library yii2-mongodb-doctrine

Doctrine MongoDB ODM extension for Yii2

image

brunohulk/yii2-mongodb-doctrine

Doctrine MongoDB ODM extension for Yii2

  • Tuesday, January 2, 2018
  • by borgesbruno
  • Repository
  • 1 Watchers
  • 1 Stars
  • 125 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 33 % Grown

The README.md

Yii2 extension for using MongoDB and Doctrine

Latest Stable Version Downloads License, (*1)

About

This component was created with the purpose of allowing us to use all benefits of the Doctrine in Yii2 using the MongoDB ODM version. There are others solutions which use MongoDB and the active record pattern from Yii, but the vast Doctrine documentation and its better way to deal with embedded documents made its case., (*2)

Installation

Require the library with Composer:, (*3)

composer require brunohulk/yii2-mongodb-doctrine

Then, to activate the component, you have to add the follow entry inside the web.php file replacing the default database params by your customise data:, (*4)

'doctrineOdm' => [
    'class' => 'brunohulk\Yii2MongodbOdm\DoctrineODM',
    'dsn' => 'mongodb://mongodb:27017', #DSN string connection
    'dbname' => 'database_name'  #Database name,
    'documentsDir' => __DIR__ . '/../../documents/', # Directory which stores your mapped collections
    'runtimeDir' =>  __DIR__ . '/../../runtime/' # The Yii2 runtime dir or other directory to store the Doctrine extra files
]

Usage

To start using the Document manager all you have to do is call the method below in any place you desire, like a controller:, (*5)

class User extends Controller
{
    private $documentManager;

    public function init()
    {
        $this->documentManager = Yii::$app->doctrineOdm->getDocumentManager();
    }

    public function actionCreate()
    {
        $user = new User;
        $user->name = "Bruno";

        $this->documentManager->persist($user);
        $this->documentManager->flush();

    }

For the last step, is necessary to create a documents folder within the common directory in your Yii project, all the documents mapped must be there, the following example is related to previous doc block., (*6)

/**
 * @ODM\Document(collection="user")
 */
class User
{
    /**
     * @ODM\Id
     */
    public $id;

    /**
     * @ODM\Field(name="name", type="string")
     */
    public $name;

}

Special thanks for David Rocha, (*7)

The Versions

02/01 2018

dev-master

9999999-dev

Doctrine MongoDB ODM extension for Yii2

  Sources   Download

MIT

The Requires

 

by Bruno Borges

11/10 2017

1.1.0

1.1.0.0

Doctrine MongoDB ODM extension for Yii2

  Sources   Download

MIT

The Requires

 

by Bruno Borges

08/10 2017

1.0.1

1.0.1.0

Doctrine MongoDB ODM extension for Yii2

  Sources   Download

MIT

The Requires

 

by Bruno Borges

08/10 2017

1.0.0

1.0.0.0

Doctrine MongoDB ODM extension for Yii2

  Sources   Download

The Requires

 

by Bruno Borges