Reputation: 1970
I'm pretty new to Symfony2. I can't figure out what's going on. This code (set up to test if the bundle can be detected):
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) );
}
}
works, rendering a simple map, while this code (the real code that involves embedding a controller to render a map with data)
<?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');
}
}
gives me this error: "An exception has been thrown during the rendering of a template ("Bundle "LocalFarmBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?") in KrewMediaLocalFarmBundle:Default:maptest.html.twig at line 3."
Both maptest.html.twig and map.html.twig are in the same folder in the LocalFarmBundle. I wonder why the bundle is found in the first piece of code but not in the second. The relevant routing is this
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')) %}
The controller for '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
) );
Any help would be appreciated in figuring out this problem.
Upvotes: 2
Views: 2801
Reputation: 12033
render
tag requires full name of bundle, so change
{% render(controller( 'LocalFarmBundle:Map:basic')) %}
to
{% render(controller( 'KrewMediaLocalFarmBundle:Map:basic')) %}
Upvotes: 6