symfony-2.1

Validating dynamically loaded choices in Symfony 2

前提是你 提交于 2019-11-27 01:25:22
问题 I have a choice field type named *sub_choice* in my form whose choices will be dynamically loaded through AJAX depending on the selected value of the parent choice field, named *parent_choice*. Loading the choices works perfectly but I'm encountering a problem when validating the value of the sub_choice upon submission. It gives a "This value is not valid" validation error since the submitted value is not in the choices of the sub_choice field when it was built. So is there a way I can

Too much data with var_dump in symfony2 doctrine2

被刻印的时光 ゝ 提交于 2019-11-26 21:31:10
I have around 40 entities and many bidirectional relationships. Whenever i use var_dump($user) or any entity my browser gets loaded with too much data of arrays and variables then it just crashed. i want to whats the problem. The data is being inserted fine. Can i cause issue in production. mgiagnoni Replace var_dump() with the debug method dump() provided by Doctrine Common . \Doctrine\Common\Util\Debug::dump($user); It works for single objects and Doctrine collections and should prevent browser displaying issues you are having. well formatted : echo '<pre>'; \Doctrine\Common\Util\Debug::dump

Deep clone Doctrine entity with related entities

天涯浪子 提交于 2019-11-26 20:33:36
I have created an entity A with OneToMany relation to B , which have relation OneToMany to C . I have to clone this A entity and set it in database with new id. Also all deep relations should be cloned with new ids too. What have I tried is to set A id to null : $A = clone $A_original; $A->setId(null); $em->persist($A); It creates new record in A table, but does not in B and C . What should I do to make a full copy of A entity ? You have to implement a __clone() method in your entities that sets the id to null and clones the relations if desired. Because if you keep the id in the related

Adding additional persist calls to preUpdate call in Symfony 2.1

北城余情 提交于 2019-11-26 17:01:34
问题 I have a preUpdate listener in my app. When it is fired I want it to create some additional records. A simplified example of the basic functionality is below. In this current implementation it would appear that the new events are not being persisted. Are there other calls I need to be making here? Thanks. public function preUpdate(Event\LifecycleEventArgs $eventArgs) { $em = $eventArgs->getEntityManager(); $uow = $em->getUnitOfWork(); $entity = $eventArgs->getEntity(); $updateArray =

MySQL Illegal mix of collations

北战南征 提交于 2019-11-26 16:07:58
问题 After viewing my prod logs, I have some error mentionning : [2012-08-31 15:56:43] request.CRITICAL: Doctrine\DBAL\DBALException: An exception occurred while executing 'SELECT t0.username ....... FROM fos_user t0 WHERE t0.username = ?' with params {"1":"Nrv\u29e7Kasi"}: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' Alghout i have UTF-8 default under the doctrine cfg : doctrine: dbal: charset: UTF8

JMSSerializerBundle. no control over third party meta data

本秂侑毒 提交于 2019-11-26 15:54:53
问题 I have two entities I wish to serialize with the JMSSerializerBundle. The Music Entity has a mapping-file with exclusion_policy: NONE . The Music entity has a field of the entity User from FOSUserBundle . The User entity has a mapping-file with exclusion_policy: ALL with a few fields set to expose: true , so they will be serialized. The problem is, the User field gets fully serialized. It does not matter if I change the mapping-file of the User entity. This is how it looks: #My/Bundle

How to get list of all routes of a controller in Symfony2?

早过忘川 提交于 2019-11-26 15:44:34
问题 I have a controller which implements all routes/URL(s) . I had the idea to offer a generic index over all help-pages. Is there a way to get all routes defined by a controller (from within a controller) in Symfony2 ? 回答1: You could get all of the routes, then create an array from that and then pass the routes for that controller to your twig. It's not a pretty way but it works.. for 2.1 anyways.. /** @var $router \Symfony\Component\Routing\Router */ $router = $this->container->get('router'); /

Too much data with var_dump in symfony2 doctrine2

孤街醉人 提交于 2019-11-26 12:18:19
问题 I have around 40 entities and many bidirectional relationships. Whenever i use var_dump($user) or any entity my browser gets loaded with too much data of arrays and variables then it just crashed. i want to whats the problem. The data is being inserted fine. Can i cause issue in production. 回答1: Replace var_dump() with the debug method dump() provided by Doctrine Common. \Doctrine\Common\Util\Debug::dump($user); It works for single objects and Doctrine collections and should prevent browser

Deep clone Doctrine entity with related entities

冷暖自知 提交于 2019-11-26 05:35:00
问题 I have created an entity A with OneToMany relation to B , which have relation OneToMany to C . I have to clone this A entity and set it in database with new id. Also all deep relations should be cloned with new ids too. What have I tried is to set A id to null : $A = clone $A_original; $A->setId(null); $em->persist($A); It creates new record in A table, but does not in B and C . What should I do to make a full copy of A entity ? 回答1: You have to implement a __clone() method in your entities