2

我对 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.php 文件的 registerBundles() 方法中) ?") 在第 3 行的 KrewMediaLocalFarmBundle:Default:maptest.html.twig 中。"

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 
    ) );

任何帮助将不胜感激找出这个问题。

4

1 回答 1

6

render标签需要包的全名,所以改变

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

{% render(controller( 'KrewMediaLocalFarmBundle:Map:basic')) %} 
于 2013-08-02T05:24:31.527 回答