捆绑不存在:Symfony2

时间:2013-08-02 05:04:38

标签: symfony controller bundle

我对Symfony2很新。我无法弄清楚发生了什么。此代码(设置为测试是否可以检测到捆绑包):     

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Ivory\GoogleMap\Overlays\Animation;
use Ivory\GoogleMap\Overlays\Marker;

class DefaultController extends Controller {

public function mapAction() {
    $map = $this->get ( 'ivory_google_map.map' );
        return $this->render ( 'KrewMediaLocalFarmBundle:Default:map.html.twig', array('map' => $map) );
  }
}

工作,渲染一个简单的地图,而这个代码(涉及嵌入控制器以使用数据渲染地图的真实代码)

<?php
// localfarm/src/KrewMedia/Bundle/LocalFarmBundle/Controller/DefaultController.php
namespace KrewMedia\Bundle\LocalFarmBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Ivory\GoogleMap\Overlays\Animation;
use Ivory\GoogleMap\Overlays\Marker;

class DefaultController extends Controller {

public function mapAction() {
    //$map = $this->get ( 'ivory_google_map.map' );
        return $this->render ( 'KrewMediaLocalFarmBundle:Default:maptest.html.twig');
  }
}

给了我这个错误:“在渲染模板期间抛出了一个异常(”Bundle“LocalFarmBundle”不存在或者没有启用。也许你忘了将它添加到AppKernel的registerBundles()方法中.php文件?“)在KrewMediaLocalFarmBundle中:默认:maptest.html.twig在第3行。”

maptest.html.twig和map.html.twig都位于LocalFarmBundle的同一文件夹中。我想知道为什么捆绑包在第一段代码中找到而在第二段没有。相关路由就是这个

krew_media_local_farm_homepage:
    pattern:  /index
    defaults: { _controller: KrewMediaLocalFarmBundle:Default:index }

krew_media_local_farm_map:
     pattern:  /map
     defaults: { _controller: KrewMediaLocalFarmBundle:Default:map }

krew_media_basic_map:
     pattern:  /map/basic
     defaults: { _controller: KrewMediaLocalFarmBundle:Map:basic }

map.html.twig:

{{ google_map_container(map) }}

{{ google_map_js(map) }}

maptest.html.twig:

Map Test

{% render(controller( 'LocalFarmBundle:Map:basic')) %} 

'LocalFarmBundle:Map:basic'的控制器:

public function basicAction() {
    // set up map
    $map = $this->get ( 'ivory_google_map.map' );

    // Get User geo info
    $user = $this->getUser ();

    if (isset ( $user )) { // check to see if logged in: map is useless without it
        $map->setAutoZoom ( true );
        $map->setStylesheetOption('width', '500px');
        $map->setStylesheetOption('height', '500px');


        $radius = 1;

        // get repository for user class
        $coordList = $this->container->get ( 'sylius.repository.user' )->findUsersNearUser ( $user, $radius );

        // set user marker

        $this->placeMarker ( $user, "/assets/img/home.png", $map );

        if (! empty ( $coordList )) {
            foreach ( $coordList as $geo ) {
                $this->placeMarker ( $geo, "/assets/img/neighbor.png", $map );
            }
        }

        // get furthest distance
        $dist = $this->getFurthestDistance ( $user, $coordList );

        // set invisible boundary markers
        $this->addBoundaries ( $user, $dist, $map );

        // render the map
    } else {
        echo "You are not logged in. Please log in and try again.";
    }


        return $this->render ( 'KrewMediaLocalFarmBundle:Default:map.html.twig', array (
            'map' => $map 
    ) );

在弄清楚这个问题时,我们将不胜感激。

1 个答案:

答案 0 :(得分:6)

render标记需要包的全名,因此请更改

{% render(controller( 'LocalFarmBundle:Map:basic')) %} 

{% render(controller( 'KrewMediaLocalFarmBundle:Map:basic')) %}