PHP code example of brunohulk / yii2-mongodb-doctrine

1. Go to this page and download the library: Download brunohulk/yii2-mongodb-doctrine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brunohulk / yii2-mongodb-doctrine example snippets


'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
]

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();

    }


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

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

}