gpt4 book ai didi

php - Symfony 找不到模板文件

转载 作者:可可西里 更新时间:2023-10-31 22:11:01 25 4
gpt4 key购买 nike

我已按照与 Symfony 安装相关的所有步骤进行操作,并尝试了 Symfony 书中的示例(由 Symfony 网站提供)。目前我在 Controller 第 (5) 章,我尝试以下代码:

namespace MyBundle\FrontBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class HelloController extends Controller
{
public function indexAction($name, Request $request)
{
return $this->redirect($this->generateUrl('front_buy'), 301);
}

public function buyAction(Request $request)
{
return $this->render(
'Hello/buy.html.twig',
array(
'name' => 'Nikos'
)
);
}
}

但我收到以下错误:

INFO - Matched route "front_buy" (parameters: "_controller": "MyBundle\FrontBundle\Controller\HelloController::buyAction", "_route": "front_buy")
CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Unable to find template "Hello/buy.html.twig"." at /var/www/projects/symfony/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128

上下文:{“异常”:“对象(InvalidArgumentException)”}

我知道这不是什么花哨的事情,但我不知道如何解决这个问题。

我的 View 文件在以下路径下:./src/MyBundle/FrontBundle/Resources/views/Hello/buy.html.twig

最佳答案

您需要使用以下语法呈现它:

$this->render('AcmeBlogBundle:Blog:index.html.twig')

或者用这个语法

$this->render('@BlogBundle/Blog/index.html.twig')

一个例子:

$this->render('@FrontBundle/Hello/buy.html.twig) 

更多信息可以在 documentation 上找到, 也指 symfonys best practices模板应存储在 app/Ressources/views

关于php - Symfony 找不到模板文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com