1

I would like to display an image which is in my database. But I have error:

"Unrecognized field: name"

I made a entity:

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;
    
/**
 * @ORM\Column(type="string", length=100)
 */
private $title;
 
/**
 * @ORM\Column(type="string")
 */
private $description;
    
/**
 * @ORM\Column(type="blob", nullable=true)
 */
private $image;
    
/**
 * @ORM\Column(type="date")
 */
private $dataStart;
  
/**
 * @ORM\Column(type="date")
 */
private $dataEnd;

And this is my controller:

/**
 * @Route(
 *      "/promotion",
 *      name = "pizza_promotion"
 * )
 * 
 * @Template
 */
public function promotionAction() {
       
    $RepoPromotion = $this->getDoctrine()->getRepository('PizzaBundle:Promotion');
        
    $rowsPromotion = $RepoPromotion->findAll();
    $rowsImage = $RepoPromotion->findBy(array('name' => 'image'));
      
    if(!empty($rowsImage)) {
        $respons = base64_decode($rowsImage);
    }
        
    return array(
        'rowsPromotion' => $rowsPromotion,
        'respons' => $respons
    );
}

But when I want display image with my twig

{% for entry in response %}
    <img src="data:image/jpeg;base64,{{ entry.image }}" alt="HTML5 Icon"> zł</li>
{% endfor %}

I have error - "Unrecognized field: name"

3
  • $RepoPromotion->findBy(array('name' => 'image')); can't work. You have to set a key/value in the array like array("image" => 1). But I think that you have to use your $rowsPromotion variable in your twig template to get all your images Commented May 3, 2017 at 18:09
  • Yes, of course. But if I used {% for entry in rowsPromotion %} <tr> <td> <img src="data:image/jpeg;base64,{{ entry.image }}"> </td> </tr> {% endfor %} I have not display image only this I have "Resource id #939" this is value in database. Probably I must use base64 decode, but twig have not a filter base64. Therefore I must download this value in controller and use base64 but this way i'm not leaving. Commented May 3, 2017 at 18:31
  • If you have some troubles with encode and decode I suggest you to use github.com/dustin10/VichUploaderBundle. It will be easier to manage images Commented May 3, 2017 at 20:07

1 Answer 1

1

Problem is with your find:

$rowsImage = $RepoPromotion->findBy(array('name' => 'image'));

Based on your entity you likely want:

$rowsImage = $RepoPromotion->findBy(array('title' => 'image'));

But basically it is saying that your Promotion repo doesnt have a property name to search by.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.