<small id='GdSv0'></small><noframes id='GdSv0'>

<tfoot id='GdSv0'></tfoot>

    1. <i id='GdSv0'><tr id='GdSv0'><dt id='GdSv0'><q id='GdSv0'><span id='GdSv0'><b id='GdSv0'><form id='GdSv0'><ins id='GdSv0'></ins><ul id='GdSv0'></ul><sub id='GdSv0'></sub></form><legend id='GdSv0'></legend><bdo id='GdSv0'><pre id='GdSv0'><center id='GdSv0'></center></pre></bdo></b><th id='GdSv0'></th></span></q></dt></tr></i><div id='GdSv0'><tfoot id='GdSv0'></tfoot><dl id='GdSv0'><fieldset id='GdSv0'></fieldset></dl></div>
      <legend id='GdSv0'><style id='GdSv0'><dir id='GdSv0'><q id='GdSv0'></q></dir></style></legend>
        <bdo id='GdSv0'></bdo><ul id='GdSv0'></ul>

    2. 如何在 Symfony2 项目中配置扩展 PersistentObject 的 Doctrine2 实体?

      How do I configure a Doctrine2 entity which extends PersistentObject within Symfony2 project?(如何在 Symfony2 项目中配置扩展 PersistentObject 的 Doctrine2 实体?)
    3. <i id='Z7pec'><tr id='Z7pec'><dt id='Z7pec'><q id='Z7pec'><span id='Z7pec'><b id='Z7pec'><form id='Z7pec'><ins id='Z7pec'></ins><ul id='Z7pec'></ul><sub id='Z7pec'></sub></form><legend id='Z7pec'></legend><bdo id='Z7pec'><pre id='Z7pec'><center id='Z7pec'></center></pre></bdo></b><th id='Z7pec'></th></span></q></dt></tr></i><div id='Z7pec'><tfoot id='Z7pec'></tfoot><dl id='Z7pec'><fieldset id='Z7pec'></fieldset></dl></div>
        <bdo id='Z7pec'></bdo><ul id='Z7pec'></ul>
          <tbody id='Z7pec'></tbody>

          • <tfoot id='Z7pec'></tfoot>

            1. <small id='Z7pec'></small><noframes id='Z7pec'>

              <legend id='Z7pec'><style id='Z7pec'><dir id='Z7pec'><q id='Z7pec'></q></dir></style></legend>
                本文介绍了如何在 Symfony2 项目中配置扩展 PersistentObject 的 Doctrine2 实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我希望能够使用这里描述的 PersistentObject http://www.doctrine-project.org/blog/a-doctrine-orm-odm-base-class.html 在 Symfony2 项目开发期间,避免创建和删除 getter 和在数据库和实体设计不断变化的同时,setter 无休止地进行.

                I would like to be able to use the PersistentObject described here http://www.doctrine-project.org/blog/a-doctrine-orm-odm-base-class.html during development of a Symfony2 project, to avoid creating and deleting getters and setters endlessly whilst the database and entity design are in flux.

                如简要文档(下面的代码引用)中所建议的那样,在 Symfony2 项目中的何处配置"ObjectManager?它应该在控制器中吗?如果是,它会是什么样子?

                Where in a Symfony2 project does one 'configure' the ObjectManager, as suggested in the brief documentation (code quote below)? Should it be in the controller, and if so, what would it look like?

                 $entityManager = EntityManager::create(...);
                 PersistentObject::setObjectManager($entityManager);
                

                我找不到任何工作示例(尽管我确实在 stackoverflow 上找到了 Zend2 框架的类似示例:在 Zend 框架中使用来自 Doctrine 的 PersistentObject

                I cannot find any working examples (although I did find this parallels example for the Zend2 framework on stackoverflow: Using PersistentObject from Doctrine in Zend Framework

                感谢您的时间!

                推荐答案

                PersistentObject 是一个不需要手动持久化的对象.因此,它使用 php 的 __call() 方法提供了神奇的 getter 和 setter.

                The PersistentObject is an object which you don't manually have to persist. It thereby provides magic getters and setters using php's __call() method.

                您只需在实体类中扩展对象并在控制器中使用它.无需生成 getter 和 setter.

                You simply extend the Object in your entity class and use it inside your controller. without the need to generate getters and setters.

                示例实体

                <?php
                namespace VendorYourBundleYourEntity;
                
                use DoctrineCommonPersistencePersistentObject; 
                use DoctrineCommonPersistenceObjectManager;
                use DoctrineORMMapping as ORM;
                
                class YourEntity extends PersistentObject
                {
                
                   // i added the constructor in order to save the setObjectManager() 
                   // call in the the controller
                
                   public function __construct(ObjectManager $om)
                   {
                       $this->setObjectManager($om);
                   }
                
                   /** 
                    * @ORMId  
                    * @ORMColumn(type="integer")
                    * @ORMGeneratedValue(strategy="AUTO")
                    */
                   protected $id;
                
                   /**
                    * @ORMColumn(type="string", length=100)
                    */
                   protected $name;
                
                   // ... more properties
                
                }
                

                示例控制器操作

                class YourController extends Controller
                {
                    public function yourAction($name)
                    {
                        $em = $this->get('doctrine')->getManager('default');
                
                        $entity = new YourEntity($em);   // __construct calls setObjectManager($em)
                
                        $entity->setName($name);         // magic setter is used here
                
                        // ... no need for $em->persist($entity);
                
                        $em->flush();                    // $entity is being persisted.
                    }
                
                    // ...
                

                您可以使用 ...

                 $em = $this->get('doctrine')->getManager();          // gets default manager
                 $em = $this->get('doctrine')->getManager('default'); // same as above
                 $em = $this->getDoctrine()->getManager();            // using alias 
                

                这篇关于如何在 Symfony2 项目中配置扩展 PersistentObject 的 Doctrine2 实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                How to parse django style template tags(如何解析 django 样式模板标签)
                What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                php in background exec() function(php 后台 exec() 函数)
                  <tbody id='BOorE'></tbody>

                <small id='BOorE'></small><noframes id='BOorE'>

              • <legend id='BOorE'><style id='BOorE'><dir id='BOorE'><q id='BOorE'></q></dir></style></legend>

                      <bdo id='BOorE'></bdo><ul id='BOorE'></ul>
                      <i id='BOorE'><tr id='BOorE'><dt id='BOorE'><q id='BOorE'><span id='BOorE'><b id='BOorE'><form id='BOorE'><ins id='BOorE'></ins><ul id='BOorE'></ul><sub id='BOorE'></sub></form><legend id='BOorE'></legend><bdo id='BOorE'><pre id='BOorE'><center id='BOorE'></center></pre></bdo></b><th id='BOorE'></th></span></q></dt></tr></i><div id='BOorE'><tfoot id='BOorE'></tfoot><dl id='BOorE'><fieldset id='BOorE'></fieldset></dl></div>

                        <tfoot id='BOorE'></tfoot>