用树枝中的资产加载图像

时间:2017-09-19 09:12:55

标签: php symfony twig

我想在我的树枝上加载一张图片,但它没有显示任何显示图片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'));
    }
}

我的图片文件夹位于根目录

3 个答案:

答案 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(...)然后重试。