Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从其他捆绑包嵌入Symfony控制器_Php_Symfony_Twig - Fatal编程技术网

Php 从其他捆绑包嵌入Symfony控制器

Php 从其他捆绑包嵌入Symfony控制器,php,symfony,twig,Php,Symfony,Twig,这似乎是一个有趣的问题,我不确定我是否遗漏了什么,因为它应该很简单,但事实并非如此 脚本 我有一个名为AcmePageBundle 另一个名为AcmeGalleryBundle 我想将AcmeGalleryBundlebundle使用到AcmePageBundle 代码 AcmeGalleryBundle\Controller\DisplayController.php AcmeGalleryBundle\Resources\views\Display\embed.html.twig {%用于

这似乎是一个有趣的问题,我不确定我是否遗漏了什么,因为它应该很简单,但事实并非如此

脚本
  • 我有一个名为
    AcmePageBundle
  • 另一个名为
    AcmeGalleryBundle
  • 我想将
    AcmeGalleryBundle
    bundle使用到
    AcmePageBundle
  • 代码 AcmeGalleryBundle\Controller\DisplayController.php AcmeGalleryBundle\Resources\views\Display\embed.html.twig
    
    {%用于画廊中的照片。照片%}
    {%endfor%}
    
    AcmePageBundle\Resources\views\Default\index.html.twig
    {#…额外的HTML内容#}
    画廊
    {{render(controller('AcmeGalleryBundle:Display:embed'{
    “galleryId”:123
    })) }}
    {#HTML内容的其余部分}
    
    错误 当试图呈现使用
    AcmePageBundle:Default:index.html.twig
    的页面时,我得到

    在第18行的AcmePageBundle:Default:index.html.twig中呈现模板(“类'AcmeGalleryBundle'不存在”)时引发异常

    当然,
    AcmeGalleryBundle
    确实存在。我怀疑我遗漏了一个范围问题

    故障排除
  • 确保
    AcmeGalleryBundle
    加载到
    AppKernel.php
    文件中
  • 尝试将
    use Acme\GalleryBundle
    添加到
    AcmePageBundle.php
    bundle文件的顶部
  • 我已经添加了我自己的评论-这实际上可能是一个bug

  • 我遗漏了什么明显的东西吗?

    我的错误是这样的:

    $gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle')->find($galleryId);
    
    命令
    getRepository('AcmeGalleryBundle')
    需要包含我试图加载存储库的实体。正确的代码是:

    $gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle:Gallery')->find($galleryId);
    
    我错误地认为这是渲染(控制器(…)功能的问题。修复后,一切正常。下次我应该仔细看看我的堆栈跟踪

    {# ... extra HTML content #}
      <h2>Gallery</h2>
      {{ render(controller('AcmeGalleryBundle:Display:embed', {
          'galleryId': 123
      })) }}
    {# rest of the HTML content #}
    
    $gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle')->find($galleryId);
    
    $gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle:Gallery')->find($galleryId);