php - Dispaly Blob image from database using Symfony Twig -
i trying display images each blog post. have them set displaying blog name, excerpt , published date, struggling images have stored blobs. have attached code, in 3 parts: entity, has set , variables; index.html.twig file, front end (how displaying image); , post.orm.yml file, set type of item image is, i.e., blob.
post entity
/**  * set image  *  * @param /post/blob $image  *  * @return post  */ public function setimage($image) {     $this->image = $image;      return $this; }  /**  * image  *  * @return post/blob  */ public function getimage() {     return $this->image; } index.html.twig
{{post.image}} post.orm.yml
shannon\blogbundle\entity\post:     type: entity     table: null     repositoryclass: shannon\blogbundle\repository\postrepository     id:         id:             type: integer             id: true             generator:                 strategy: auto     fields:         title:             type: string             length: '255'         body:             type: text         publishedat:             type: datetime             column: published_at         image:             type:image     lifecyclecallbacks: {  } postcontroller.php
public function imageaction($id) {     $image =  $this->getdoctrine()->getrepository('shannonblogbundle:image')->findoneby(array('id'=> $id));
     return $this->render('index.html.twig', array('image' => $image)); } }     public function imageaction($id) {     $image =  $this->getdoctrine()->getrepository('shannonblogbundle:image')->findoneby(array('id'=> $id));
     return $this->render('index.html.twig', array('image' => $image)``); }
you need encode image in base64 , embed in html:
<img  src="data:image/png;base64,{{ imagebase64 }}" /> 
Comments
Post a Comment