brunohulk/yii2-mongodb-doctrine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brunohulk/yii2-mongodb-doctrine

最新稳定版本:1.1.0

Composer 安装命令:

composer require brunohulk/yii2-mongodb-doctrine

包简介

Doctrine MongoDB ODM extension for Yii2

README 文档

README

Latest Stable Version Downloads License

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.

Installation

Require the library with Composer:

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:

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

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.

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

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

}

Special thanks for David Rocha

统计信息

  • 总下载量: 4.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-08