我想在我的树枝上加载一张图片,但它没有显示任何显示图片alt
这是我的list.html.twig,它将加载图片:
<img src="{{ asset('images/2.jpg') }}" alt="Symfony" />
这是我的控制者:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class InheritanceController extends Controller
{
/**
* @Route("/inherit")
*/
public function inheritAction(){
return new Response($this->render('article/list.html.twig'));
}
}
我的图片文件夹位于根目录
中答案 0 :(得分:1)
只有当您的图片存在于asset()
文件夹中时,您才能在树枝中使用web/images
功能及其默认配置,然后您可以通过{{ asset('images/<image_name>') }}
答案 1 :(得分:0)
通过控制台安装资产:php app/console assets:install --symlink
答案 2 :(得分:0)
方法$this->render()
已经返回Response
个实例,只需将其更改为return $this->render(...)
然后重试。