Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:51:11+00:00 2026-06-16T05:51:11+00:00

I have an Image entity: class Image { /** * @ORM\Id * @ORM\Column(type=integer) *

  • 0

I have an Image entity:

class Image {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", nullable=true)
 */
protected $location;

/**
 * @Assert\File(maxSize="6000000")
 */
protected $file;

public function __toString()
{
    return $this->getLocation()
}

//............
}

And I want to allow users to delete select images and delete them. I made an ImageSelectType :

class ImageSelectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add(PROBLEM_IS_HERE, 'entity', array(
                    'class' => 'BloggerBlogBundle:Image',
            )
        )
        ;
}

//.......
}

However, I seem to be unable to understand exactly how Entity Type works. If I put ‘location’ or some property as first argument of $builder->add function, I get this for example:

object(Blogger\BlogBundle\Entity\Image)[316]
  protected 'id' => null
  protected 'location' => 
    object(Blogger\BlogBundle\Entity\Image)[79]
      protected 'id' => int 16
      protected 'location' => string '8a307aadd466f1b92b149d3f79069f5a1abc9cd3.png'     (length=44)
      protected 'file' => null
  protected 'file' => null

So It actually puts whole object into Location property of empty Image object. If I would have placed ‘id’ as first argument, I would get exactly the same result except object would be stored in $image->id. What am I supposed to enter as first argument of $builder-add to actually receive just the object itself?

Here is my action code if it’s relevant:

public function imageDeleteAction()
{
$image = new Image();
    $request = $this->getRequest();

    $em = $this->getDoctrine()->getEntityManager();

    $form = $this->createForm(new ImageSelectType(), $image);
    $form->bindRequest($request);

    var_dump($image);
    exit;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:51:12+00:00Added an answer on June 16, 2026 at 5:51 am

    You need to create a type just for Image, which breaks out it’s properties in to separate fields, then use that AbstractType as the class for your other one.

    You essentially want a collection of forms.

    Update

    I miss read your question a bit wrong the first time.

    It looks like what you actually want to do is create something like an ImageGroup object which has an array of Images. Then that would be the target you send in to $this->createForm, and you would set that field in your PROBLEM_IS_HERE.

    // Entity/ImageGroup.php
    class ImageGroup
    {
        protected $images;
    
        public function __construct($images) {
           $this->images = $images;
        }
    
        public function getImages() { return $this->image; }
        public function setImages($images) { $this->images = $images; }
    }
    
    // ImageSelectType
    class ImageSelectType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
                ->add('images', 'entity', array(
                        'class' => 'BloggerBlogBundle:Image',
                )
            )
            ;
    }
    
    // Controller
    public function imageDeleteAction()
    {
        $images = $this->get('doctrine')->getRepository('MyBundle:Image')->findAll();
        $imageGroup = new ImageGroup($images);
    
        $request = $this->getRequest();
    
        $em = $this->getDoctrine()->getEntityManager();
    
        $form = $this->createForm(new ImageSelectType(), $imageGroup);
        $form->bindRequest($request);
    
        var_dump($image);
        exit;
    }
    

    Then you would have to loop through the images and figure out which ones are missing to delete them. There are a few variations on this method, but this is probably the simplest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small question by entity framework 4.1. There is interface of image DTO:
I have many to many relationship in entity framework. See image... I want to
I have a db.BlobProperty property (called Icon) in my entity which contains an image
I have an Image class that has a byte[] to contain the actual image
Is it possible to have multi-level polymorphism in SQLAlchemy? Here's an example: class Entity(Base):
What I'm attempting to do is have a Super entity class for saved products.
I have 2 Hibernate classes in a Spring-driven Application like these: @Entity public class
I have the following model (playframework): @Entity public class Album extends Model{ public Album(){
I have a product entity which has several classes (each product type has different
I have a Priority class that has a datetime column. This column has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.