I am trying to build a simple backend application based on EasyAdmin. The ORM is Doctrine.
I have set up 3 entities :
* Entity A has a unidirectional many-to-many relation to entity B
* Entity B has a one-to-one relation to entity C
* Entity C has some basic properties
In EasyAdmin I have set up the Entity A and Entity C. The purpose is to add/edit Entity B while adding/editing entity A. II found the following which is exactly what I want. symfony easyadmin one to many form.
But when I want to add an Entity B while adding Entity A, it creates a form with the appropriate fields but the form has its own save button. Which seems to conflict with the main save button. Results
Is there a working example of what I want to achieve or some documentation on how to do it ?
Regards
Christophe Absil
I think that a good idea would be to override the 'new' and 'edit' templates. You have here the official documentation to help you.
While rendering the form, you will be able to hide/add labels & buttons; in order to hide a form element, just add:
{{ form_end(form, {'render_rest': false}) }}
A final step would be to override EasyAdmin's AdminController in order to persist the second entity; this is the official page.
Good luck!
Related
Coming over from Python to do an application in SF2 and would love some help
I need to create a list of books, this has been easy and Sonata admin bundle has been really easy to setup but now I'm stuck one one section
I need the following fields:
Title
ie. Harry Potter
Description
ie. Book about wizards
Themes
ie. ['Animals' => ['Donkey', 'Cat'], 'Seasons' => ['Winter', 'Summer']]
Grammar
ie. ['Possessive pronoun' => ['my']]
The Themes and Grammar I would identify as:
Area
Target: The target (string)
Examples: list of examples (array)
Is there any Doctrine & Sonata admin related data structure that would be good to use in this situation? I do not need the "areas" to be their own models but would like to list each area target and it's examples on a template.
Thankyou!
The simplest solution is to store Area as an Entity and also Example as an entity. Then you can make many-to-one relations called "grammar" and one-to-many relation called themes both pointing to Area entity and also one-to-many relation in Area entity that points to Example entity. In Area entity I advise you to write __toString function in Area Entity. This function can return string composed with target and examples. This will let you print Area properly - for example on sonata admin list.
If you build query in Sonata Admin make sure you extend default query with left joins to Area and Example entities.
I'm working on an e-learning application and I have to categorize courses. So my Section entity is one of Tree extension. In order to retrieve all courses of a section, I made the following assoication:
/**
* #ORM\OneToMany(targetEntity="Svi\FormationBundle\Entity\Course", mappedBy="section")
*/
private $courses;
The problem is that when I try get courses in twig doing this {% if section.courses|length > 0 %}, I receive this error message
Key "courses" for array with keys "id, titre, sommaire, slug, deactivated, lft, lvl, rgt, root, __children" does not exist in SviFormationBundle:Formation:see_courses.html.twig at line 22.
I made a dump on the section object and it displayed all attributes except ones of OneToMany and ManyToOne associations. Any help please? Isn't it possible to associate other entities to a Tree entity? If so how to make a nested classification in Symfony? Thanks.
In your query, you have to explicitely add the 'join' or 'leftJoin' to the 'Course' entity.
I want to log all changes of an entity. I looked into Loggable doctrine extension as provided by the StofDoctrineExtensionsBundle.
I got it working for fields that store simple data, e.g. string and integers. But my entity also has ManyToMany relationship to another entity, e.g. Tags.
I am getting this error:
InvalidMappingException: Cannot versioned [tags] as it is collection in object - Hn\AssetDbBundle\Entity\Asset
Is there a way to log an entity with its relationships? I don't mind switching to another bundle.
Currently no bundles/extensions have this functionality out of the box. One option would be to implement it yourself. This can be done by making use of Doctrine Listeners. Particularly you need to listen to postUpdate and postPersist events - these happen when entity is updated and created and store your Tags there.
Another option is to get rid of ManyToMany relationship. For this create an intermediate entity AssetTag that would have OneToMany relationship to both Asset and Tag. After this is done, you can use EntityAudit Doctrine Extension, which supports this type of relationships.
Suppose i have an Bundle to manage anything related to advertisements.
This bundle contains an Entity Advertisement. this has an field for relation purposes: lets say relation field
Suppose i have an Entity Company and an Entity Events in different Bundles
(In companies there are companies stored and in events there are events stored.)
Case:
The entities have a relation to multiple Advertisements.
A single Advertisement has a relation to only one of the entities.
From the perspective advertisement:
I want to be able to select one of the entities (entity.id) to view or update the reference (like dropdown)
From the perspective of an event or a company:
I want to be able to select/add/delete multiple advertisements (like the symfony collection form type)
all this preferred without the use of foreign-keys.
the entities are like "modules" so there can be more than just these entities.
I think you just have to use OneToOne (For Advertisement) and OneToMany (For Company and Events) relations.
It's easy to use, read this doc : http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html
I am using sonata-admin generator for one of my project.
I want to create a form which contains fields from two tables User and User_add.
My tables are like this:
USER: id,name,age,login_id,pwd,create_at,updated_at
USER_ADD: id,user_id(FK from user),add_type,street,city,state,country,pin.
Now I want a single form so that, I should be able to insert data for both user as well as user_add using sonata admin generator.
Please suggest me some link if, I can get answer of this doubt.
Thanks in advance.
Please check http://forum.symfony-project.org/viewtopic.php?t=38120, it describes doctrine one-to-one relation between item and itemDetail and how to use sonata_type_admin to have a possibility to create itemDetail from item form.