**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
{% 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 :(得分: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" />
工作...