我可以在我的普通 php 类中使用 Doctrine Mongodb ODM 吗?
我想在我的单独项目中使用 Doctrine mongodb ODM,我想使用这个 ODM 执行所有 mongodb 相关的数据库调用。
当我的应用程序(不在交响乐中)想要添加用户对象时,我想调用用 Mongodb-ODM 编写的用户文档类
<?php
namespace Documents;
/** @Document */
class User
{
// ...
/** @Id(strategy="AUTO") */
private $id;
/** @Field(type="string") */
private $username;
}
现在我想从我单独的 php 类中调用这个类,如下所示,我们在文档中显示......
$document = new User();
$document->setUsername('abc');
$dm->persist($document);
$dm->flush();
什么在我单独的 php 类中使用这个 $dm= documentmapper 需要什么步骤?
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....
$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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你绝对可以做到!不过,如何取决于你自己。
当您创建 DocumentManager 实例时,您需要保留它。例如,如果您将其与 Zend Framework 一起使用,则可以使用 Zend_Registry 保留它。这只是一个示例,但您可以通过多种方式保存 DocumentManager。
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.