Symfony 2 - 模板路径 [英] Symfony 2 - path to template

查看:28
本文介绍了Symfony 2 - 模板路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的模板路径不起作用.我听说一切正常,应该可以正常工作,但事实并非如此.

I have no idea why my path to template isn't working. I have heard that everything is ok and it should be working, but it isn't.

..\project\src\Application\Sonata\AdminBundle\Resources\views\CRUD\list_image.html.twig

..\project\src\Application\Sonata\AdminBundle\Resources\views\CRUD\list_image.html.twig

->add('photo', null, array('template' => 'ApplicationSonataAdminBundle:CRUD:list_image.html.twig'))

但是当我尝试启动项目时,我从日志中收到此错误:

But when I try to fire the project, I get this error from log:

[2014-10-15 10:28:59] app.WARNING: 尝试为字段photo"加载模板ApplicationSonataAdminBundle:CRUD:list_image.html.twig"时发生错误,默认模板SonataAdminBundle":CRUD:base_list_field.html.twig" 被使用:无法找到模板ApplicationSonataAdminBundle:CRUD:list_image.html.twig".".[] []

[2014-10-15 10:28:59] app.WARNING: An error occured trying to load the template "ApplicationSonataAdminBundle:CRUD:list_image.html.twig" for the field "photo", the default template "SonataAdminBundle:CRUD:base_list_field.html.twig" was used instead: "Unable to find template "ApplicationSonataAdminBundle:CRUD:list_image.html.twig".". [] []

对我来说这条路没问题.我不知道为什么这不起作用.

For me this path is ok. I have no idea why this isn't working.

没有错别字,因为路径被复制了,我找错字很多很多次了.

There is no typo, because path was copied and I was looking for typo for many, many times.

请帮忙!

推荐答案

非常感谢用户 Nic.他带我找到了解决这个问题的好方法.

Big thanks for user Nic. He took me on the good way of finding the solution of this problem.

首先,在..\project\src\Application\Sonata\AdminBundle\中定义一个新文件:ApplicationSonataAdminBundle.php

First, define new file: ApplicationSonataAdminBundle.php in ..\project\src\Application\Sonata\AdminBundle\

然后在文件中:

namespace Application\Sonata\AdminBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;


class ApplicationSonataAdminBundle extends Bundle
{
    public function getParent()
    {
        return 'SonataAdminBundle';
    }
}

然后正如网卡所说,我们需要在 app/AppKernel.php 中注册我们的包:

and then as a Nic said, we need to register our bundle in app/AppKernel.php:

new Application\Sonata\AdminBundle\ApplicationSonataAdminBundle(),

感谢大家的帖子和帮助!

Thank you guys for posts and help!

这篇关于Symfony 2 - 模板路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆