开发者

can I use Doctrine Mongodb ODM in my plain php class?

开发者 https://www.devze.com 2023-03-30 01:52 出处:网络
I want to use Doctrine mongodb ODM for my separate project, I want to do all mongodb related database-calls using this ODM.

I want to use Doctrine mongodb ODM for my separate project, I want to do all mongodb related database-calls using this ODM.

When My application(not in symphony) want to add user object, I want to call User Document Class written in Mongodb-ODM

<?php

namespace Documents;

/** @Document */
class User
{
    // ...
    /** @Id(strategy="AUTO") */
    private $id;

    /** @Field(type="string") */
    private $username;
}

Now I want to call this class from my separate php classes as below we are shown in documentation.开发者_如何学Go...

$document = new User();
$document->setUsername('abc');
$dm->persist($document);
$dm->flush();

What steps are needed to use this $dm= documentmapper in my separate php classes?


You can absolutely do that! How you do it is up to you, though.

When you create your instance of DocumentManager, you need to persist it. For example, If you're using it with Zend Framework, you can persist it with Zend_Registry. This is just an example, but there are many ways you can persist your DocumentManager.

  • Storing in a statically accessed class
  • Dependency Injection
  • Global var (not really advised)
0

精彩评论

暂无评论...
验证码 换一张
取 消