doctrine-orm

Doctrine not working unless I explicitly call AnnotationDriver::getAllClassNames

别说谁变了你拦得住时间么 提交于 2020-01-24 03:53:25
问题 I'm attempting to use Doctrine ORM for the first time, and I'm following the configuration found here. Following these steps directly results in the following error: Warning: class_parents() [function.class-parents]: Class MyProject\Model\User does not exist and could not be loaded in /opt/local/lib/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222 Warning: array_reverse() expects parameter 1 to be array, boolean given in /opt/local/lib/php/Doctrine/ORM/Mapping

Entity field - queryBuilder->select()

主宰稳场 提交于 2020-01-24 00:21:06
问题 I have a problem with entity field, query builder and OneToOne relationship. When I created entity field with query_builder in form class and when I set select ('u.id, u.username') I get exception: >need array or object, integer given. When I set select('u') is fine but I get columns with OneToOne relationship and Doctrine generates x additional SELECT queries. What do I have to do? EDIT: MORE DETAILS For example I have two entity with oneToOne relation, User and Contact: <?php namespace

Doctrine nested array hydration

筅森魡賤 提交于 2020-01-23 17:49:09
问题 i've try to hydrate an nested array to entities. The array looks something like this <?php $arrData = array( 'username' => 'test', 'email' => 'test@test.at', 'images' => array( array( 'name' => 'test', 'url' => 'http://url1.test' ), array( 'name' => 'test', 'url' => 'http://url1.test' ) ) ); ?> So how you can see, there is an one to many relation between user and images. So if what i want to do, is i want do hydrate them into an User entity something like this: <?php $hydrator = new

How to set created and updated date in symfony2?

て烟熏妆下的殇ゞ 提交于 2020-01-23 09:33:06
问题 I am creating a todo app where the user can create tasks.The user has the options of inserting title, due date, completed. I want to be able to insert created and updated date automatically when the user creates the task. 回答1: A better solution is to use the Timestampable extension for Doctrine from gedmo: https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md. This extension uses lifecyclecallbacks, but it is a cleaner way to set created and updated timestamps. 回答2

Concurrent requests trying to create the same entity if not exists in Doctrine

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 03:28:09
问题 I have a function that looks like this: function findByAndCreateIfNotExists($criteria){ $entity = $this->findBy(['criteria'=>$criteria]); // this is the problem area, if request 1 is still creating the entity, request 2 won't find it yet. if (! $entity) { $entity = $this->createEntity($criteria); } return $entity; } This function is used by various requests, and I've found that concurrent requests will sometimes try to create the same entity, throwing a DBALException complaining about

How do I use Doctrine2 to work with GeoSpatial Queries using PostGIS?

走远了吗. 提交于 2020-01-22 12:44:07
问题 I have a public facing app that is based on Postgres and PostGIS. I have tried Googling for hours but have been unable to find any documentation that can show some basic geospatial stuff like getting distance between two points using Doctrine2. Not being able to use an ORM is a big deal for me in terms of determining my database of choice. Can someone show me a basic example of lets say showing all points within a radius of lets say 10 miles using Doctrine? 回答1: I wrote an article on my blog,

Is it worth using Doctrine 2 with Zend Framework?

给你一囗甜甜゛ 提交于 2020-01-22 07:30:09
问题 I know that some users use Doctrine 2 instead of Zend_Db in Zend Framework. But I don't know why. Why is Doctrine2 better than Zend_Db and why Zend_Db is not good? Thanks 回答1: (7-Mar-2013) Disclaimer: This answer is probably now a bit out of date. I'm not keeping up with the PHP community at the moment and this comparison is between Doctrine ORM v2 and Zend Framework v1. This is an apples vs. oranges comparison because they're two different things. Out-of-the-box Zend_Db is more just an

Warning: spl_object_hash() expects parameter 1 to be object, with Message

泪湿孤枕 提交于 2020-01-21 19:31:18
问题 i am getting the error when i try to flush the data, Warning: spl_object_hash() expects parameter 1 to be object along with this message Found entity of type on association Subject\Entity\Subject#user, but expecting Subject\Entity\User now here is the action i am trying to implement public function addAction() { $form = new SubjectForm(); $form->get('submit')->setAttribute('label', 'Add'); $request = $this->getRequest(); if (!$this->sessionVar) { $this->sessionVar = new SessionContainer(

Doctrine 2 - How to use objects retrieved from cache in relationships

情到浓时终转凉″ 提交于 2020-01-21 14:50:20
问题 I'm working in a project that use Doctrine 2 in Symfony 2 and I use MEMCACHE to store doctrine's results. I have a problem with objects that are retrieved from MEMCACHE. I found this post similar, but this approach not resolves my problem: Doctrine detaching, caching, and merging This is the scenario /** * This is in entity ContestRegistry * @var contest * * @ORM\ManyToOne(targetEntity="Contest", inversedBy="usersRegistered") * @ORM\JoinColumn(name="contest_id", referencedColumnName="id",

How I can get the current user into my entity classes?

本秂侑毒 提交于 2020-01-21 13:39:05
问题 I am developing my first Symfony 4 application and I migrating from Symfony 2+ and symfony 3+. Right now I am developing a back-end and all of my entity classes have a addedBy() and updatedBy() methods where I need to record the current logged in administrator. I would like to have something like an event listener where I do not have to set those methods in all of my controllers. How to accomplish this? 回答1: First, to simplify matters and help down the road I would create an interface this