2017-09-12 41 views
-2
**NewController** 
This is my **NewController** i going to fetch data from database but my image not view on my view page so i don't know how can i view image on my view page. 
This is my **NewController** i going to fetch data from database but my image not view on my view page so i don't know how can i view image on my view page. 
This is my **NewController** i going to fetch data from database but my image not view on my view page so i don't know how can i view image on my view page. 
This is my **NewController** i going to fetch data from database but my image not view on my view page so i don't know how can i view image on my view page. 
This is my **NewController** i going to fetch data from database but my image not view on my view page so i don't know how can i view image on my view page. 

<?php 


namespace AppBundle\Controller; 
use AppBundle\Entity\users; 
use AppBundle\Entity\Login; 
use AppBundle\Entity\customer; 
use AppBundle\Entity\Product; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\HttpFoundation\Session\Session; 




    class NewController extends Controller 

    { 

    /** 
    * @Route("/main", name="main") 
    */ 

    public function mainAction(Request $request) 

    { 

     $product = $this->getDoctrine() 
     ->getRepository('AppBundle:Product') 
     ->findAll(); 


      return $this->render('website/main.html.twig', array('view' => $product)); 



    } 

?> 


**main.html.twig** 
This is my **main.html.twig** i don't know how can i display my image from database on my view page. 

這是我main.html.twig我不知道我怎樣才能從我的數據庫視圖頁面上顯示我的形象頁面上查看。 這是我的main.html.twig我不知道如何在我的視圖頁面上顯示數據庫中的圖像。 這是我的main.html.twig我不知道如何在我的視圖頁面上顯示數據庫中的圖像。 enter image description here圖像不symfony的

{% for key in view %} 
<table border="1"> 
     <tr> 

      <td> 
       <img src="{{ key.fileinput }}" alt="" width="100" height="100" /> 
      </td> 
      <td> 
       {{ key.productname }} 
      </td> 
      <td> 
       {{ key.productprice }} 
      </td> 

     </tr> 
     </table> 
    {% endfor %} 


**Product.php** 

This is my **Product.php**. 

<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Product 
* 
* @ORM\Table(name="product") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") 
*/ 
class Product 
{ 
    /** 
    * @var int 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="productname", type="string", length=255) 
    */ 
    private $productname; 

    /** 
    * @var int 
    * 
    * @ORM\Column(name="productprice", type="integer") 
    */ 
    private $productprice; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="fileinput", type="string", length=255) 
    */ 
    private $fileinput; 


    /** 
    * Get id 
    * 
    * @return int 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set productname 
    * 
    * @param string $productname 
    * 
    * @return Product 
    */ 
    public function setProductname($productname) 
    { 
     $this->productname = $productname; 

     return $this; 
    } 

    /** 
    * Get productname 
    * 
    * @return string 
    */ 
    public function getProductname() 
    { 
     return $this->productname; 
    } 

    /** 
    * Set productprice 
    * 
    * @param integer $productprice 
    * 
    * @return Product 
    */ 
    public function setProductprice($productprice) 
    { 
     $this->productprice = $productprice; 

     return $this; 
    } 

    /** 
    * Get productprice 
    * 
    * @return int 
    */ 
    public function getProductprice() 
    { 
     return $this->productprice; 
    } 

    /** 
    * Set fileinput 
    * 
    * @param string $fileinput 
    * 
    * @return Product 
    */ 
    public function setFileinput($fileinput) 
    { 
     $this->fileinput = $fileinput; 

     return $this; 
    } 

    /** 
    * Get fileinput 
    * 
    * @return string 
    */ 
    public function getFileinput() 
    { 
     return $this->fileinput; 
    } 
} 
+0

可以爲你傾倒你的'key.fileinput'? –

+0

先生我曾用「」及其工作 –

回答

0

使用<img src="{{asset ("uploads/photos/" ~ key.fileinput) }}" attr="" width="100" height="100" />工作...使用<img src="{{asset ("uploads/photos/" ~ key.fileinput) }}" attr="" width="100" height="100" />奮力...使用<img src="{{asset ("uploads/photos/" ~ key.fileinput) }}" attr="" width="100" height="100" />工作...