编程语言
首页 > 编程语言> > php – Symfony错误:“在呈现模板期间抛出异常”

php – Symfony错误:“在呈现模板期间抛出异常”

作者:互联网

我想包括

<link href="{{ asset('css/mystyle.css') }}"
      rel="stylesheet"/> 

在我的twig文件中并渲染它.但它给了我未捕获的PHP异常Twig_Error_Runtime:

“An exception has been thrown during the rendering of a template
(“Asset manifest file “/../public/build/manifest.json” does not
exist.”)

它在我使用时确实有效

link href="css/mystyle.css"
          rel="stylesheet"/>

.
以下是我的控制器:

    <?php

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class WelcomeController extends AbstractController
{
    /**
     * @Route("/", name="welcome")
     */
    public function index()
    {
        return $this->render('welcome/index.html.twig');
    }
}

以下是我的树枝模板:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Let's Explore Symfony 4</title>

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet"
          href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
          integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"
          crossorigin="anonymous">

    <link href="{{ asset('css/mystyle.css') }}"
          rel="stylesheet"/>

</head>

<body>
<header>
    <nav class="navbar navbar-expand-sm navbar-dark bg-dark">
        <div class="container">

            <a class="navbar-brand" href="#">Home</a>

            <div class="collapse navbar-collapse">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="#">Hello Page</a>
                    </li>
                </ul>
            </div>
        </div>

    </nav>
</header>

<main role="main" class="container main">
    <div>
        <h1>Let's Explore Symfony 4</h1>
        <p class="lead">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras rutrum sapien mauris, venenatis
            facilisis neque tincidunt vel. Maecenas vel felis vel turpis scelerisque eleifend. Fusce nec purus egestas,
            efficitur nisi ac, ultrices nulla. Pellentesque eu mollis tortor, in mollis nisl. Maecenas rhoncus quam non
            lacinia mollis.</p>
    </div>
</main>
</body>
</html>

我该如何解决这个问题?

解决方法:

执行以下命令:

yarn add --dev @symfony/webpack-encore

yarn add webpack-notifier --dev

yarn encore dev

它将生成manifest.json文件

标签:symfony4,php,symfony,twig,rendering
来源: https://codeday.me/bug/20191006/1861582.html