【发布时间】:2014-10-22 19:16:20
【问题描述】:
这似乎是一个有趣的问题,我不确定我是否遗漏了什么,因为它应该很简单,但事实并非如此。
场景
- 我有一个名为
AcmePageBundle的包 - 另一个包名为
AcmeGalleryBundle - 我想将load an embedded view from the controller 使用
AcmeGalleryBundle捆绑到AcmePageBundle上的模板文件中
代码
AcmeGalleryBundle\Controller\DisplayController.php
class DisplayController extends Controller
{
public function embedAction($galleryId)
{
$gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle')->find($galleryId);
if (!$gallery) {
throw $this->createNotFoundException('Gallery could not be found');
}
return $this->render('AcmeGalleryBundle:Display:embed.html.twig', array(
'gallery' => $gallery,
));
}
}
AcmeGalleryBundle\Resources\views\Display\embed.html.twig
<div class="gallery">
{% for photo in gallery.photos %}
<a href="{{ photo.webPath }}" rel="shadowbox[gallery];">
<img src="{{ photo.webPath }}" height="100" width="100">
</a>
{% endfor %}
</div>
AcmePageBundle\Resources\views\Default\index.html.twig
{# ... extra HTML content #}
<h2>Gallery</h2>
{{ render(controller('AcmeGalleryBundle:Display:embed', {
'galleryId': 123
})) }}
{# rest of the HTML content #}
错误
当尝试渲染使用 AcmePageBundle:Default:index.html.twig 的页面时,我得到了
在 AcmePageBundle:Default:index.html.twig 的第 18 行渲染模板(“类 'AcmeGalleryBundle' 不存在”)期间引发了异常。
当然,AcmeGalleryBundle 确实存在。我怀疑我在某个地方遗漏了一个范围问题。
疑难解答
- 确保
AcmeGalleryBundle加载到AppKernel.php文件中 - 尝试将
use Acme\GalleryBundle添加到AcmePageBundle.php捆绑文件的顶部。 - Found an issue on GitHub relating to the problem with no response from the devs yet.我已经添加了自己的 cmets - 这实际上可能是一个错误。
我错过了什么明显的东西吗?
【问题讨论】: