doctrine

Symfony2 Form Events Listener and Data Transformer Error Cannot instantiate interface Doctrine\…\ObjectManager

混江龙づ霸主 提交于 2020-01-05 09:27:55
问题 I'm working on a Symfony 2.3 form which require that a field be only available on "create new" mode. The field is a link in a Many-to-One relationship, i've managed to change the dropdown list by using a jQuery AutoComplete for ease of use via a FormEvents::PRE_SET_DATA event ,however the FormEvents::PRE_SUBMIT which is to turn the ID supplied into an object require a Doctrine ObjectManager. This turn to be an Interface and throw the 'Cannot instantiate interface Doctrine\Common\Persistence

Symfony2 class_parents() Class does not exist error

微笑、不失礼 提交于 2020-01-05 07:54:25
问题 I am trying to get data from a table with Doctrine 2 in a Symfony2 application. Code that works on my development machine throws an error when deployed to a production server. Here is one of my controllers. public function listEntitiesAction($entity, Request $request) { $repository = $this->getDoctrine()->getRepository('AALCOInventoryBundle:' . $entity); $metadata = $this->getDoctrine()->getEntityManager()->getClassMetadata('AALCOInventoryBundle:' . $entity); $dataTable = new Datatable(

Symfony - Add a column to a table without losing already generated classes

霸气de小男生 提交于 2020-01-05 07:30:03
问题 How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit? If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM. 回答1: Use doctrine migrations. It allows you to modify your schema, update the database and your model without also losing the existing data in your database (in case it is relevant). http://www.symfony-project.org/doctrine/1_2/en/07-Migrations Applicable for

Symfony - Add a column to a table without losing already generated classes

ⅰ亾dé卋堺 提交于 2020-01-05 07:29:02
问题 How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit? If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM. 回答1: Use doctrine migrations. It allows you to modify your schema, update the database and your model without also losing the existing data in your database (in case it is relevant). http://www.symfony-project.org/doctrine/1_2/en/07-Migrations Applicable for

“SQLSTATE[23000]: Integrity constraint violation” with valid constraint

血红的双手。 提交于 2020-01-05 04:42:26
问题 I'm using Symfony 2 with Doctrine. I have 4 classes: Country, District, County and Local. District has a foreign key of Country; County has a foreign of District; Local has a foreign key of District. The problem is that when inserting a County (using data fixtures), I get the error SQLSTATE[23000]: Integrity constraint violation: I dumped the SQL to create the tables and constraints and got this: CREATE TABLE Country (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, insertedAt

Doctrine: Group by date ranges

时光总嘲笑我的痴心妄想 提交于 2020-01-05 04:26:25
问题 In my Symfony app I have an entity 'Project' which contains two fields: 'createdOn' (type = date) and 'individual'. An individual can occur multiple times in 'Project'. _created_On_|_individual_id 2012.12.01 | 3 2012.12.24 | 5 2013.01.10 | 9 I'm trying to build a query to count all distinct individuals grouped by 'createdOn' in such a way, that I get results sorted by month. And it must be possible to set a date range for the query. My query so far: 'SELECT p.createdOn, COUNT (DISTINCT p

Infinite loop in Doctrine event listener when trying to save additional entity

主宰稳场 提交于 2020-01-05 03:09:32
问题 I want that every time a new Distance entity (from Place_A to Place_B) is saved, the reverse distance (from Place_B to Place_A) gets inserted too into the DB. My problem is the following listener loops infinitely (hence the counter): class Listener { public $count; public function prePersist(LifecycleEventArgs $eventArgs) { if ($this->count > 5) { die(); } $entity = $eventArgs->getEntity(); if ($entity instanceof Distance) { // $this->created = microtime(true) in Distance's constructor echo

Doctrine ORM: Models not respecting case

我只是一个虾纸丫 提交于 2020-01-04 05:42:16
问题 I have a mysql database table called UserDegree, when i try to import back to PHP using Doctrine it generates a model name Userdegree, is there a way to solve this? i really can't find any good doctrine documentation. thanks! 回答1: I am not sure about your specific problem, but for the "good doctrine documentation" part, did you try the manual ? See Doctrine ORM for PHP -- I think it's actually quite good, especially compared to what you get with some other projects, that don't have much

symfony2 doctrine onetoone complete example

六月ゝ 毕业季﹏ 提交于 2020-01-04 04:43:32
问题 i try make onetoone relation from example - http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity this is second try , first is here symfony 2 doctrine relation onetoone Adres <?php /** * Created by PhpStorm. * User: grek * Date: 18.12.13 * Time: 16:33 */ namespace Miejsce\ObiektyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class Adres { /** * @var integer * @ORM\Column(type="integer") * @ORM\Id * @ORM

symfony2 doctrine onetoone complete example

*爱你&永不变心* 提交于 2020-01-04 04:43:11
问题 i try make onetoone relation from example - http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity this is second try , first is here symfony 2 doctrine relation onetoone Adres <?php /** * Created by PhpStorm. * User: grek * Date: 18.12.13 * Time: 16:33 */ namespace Miejsce\ObiektyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class Adres { /** * @var integer * @ORM\Column(type="integer") * @ORM\Id * @ORM