symfony - How to populate an ArrayCollection variable with existing data from a form? -
i'm kind of new symfony, , have question. i'm making gallery bundle (consisting of 'gallery' , 'image' entities), , here comes problem.
i can upload images use entity image corresponding file, i'd categorize images galleries. made one-to-many relationship between gallery , image entities, arraycollection $images (into gallery entity) should represents images.
now, how can populate $images variable browser ? thought of solution : add text field gallery entity, images names, , before persisting gallery entity, fetch corresponding images entities , put them variable $images, problem can't access entity manager entity..
thanks help, if need code can of course show you, if it's pretty basic.
edit: found way access entity manager entity, said unsecure. time being i'll use that, if can explain me better way, i'll take it.
you write service injected entity manager can create &/or update gallery array of $image names , have controller call rather having entity dependent on entity manager. example: (see link above how configure service in services.yml)
class gallerymanager { private $entitymanager; public function __construct(\doctrine\orm\entitymanager $entitymanager) { $this->entitymanager = $entitymanager; } public function updategalleryimages(gallery $gallery, array $imagenames) { ... } } however, i'm not sure if typing in image names best approach here. how ensure image names unique? handle names aren't found? handle duplicate names? matter how usable interface is? how efficiency - 1 query each image name? how many gallery contain?
an alternative user interface provide sort of image search/list , allow user select images results add gallery - in case selection should come array of image entities if implemented correctly. @ it's simplest, small number of images multi-selectable list box of image names although ideally user want see thumbnail previews of images they're choosing from.
a basic list box of image names (or set of checkboxes) implemented using form (data_class gallery) entity field images collection. map directly onto gallery->images , entity never need depend on entitymanager.
selecting filtered set of images more complex although can point in right direction if it's of interest you.
Comments
Post a Comment