Tuesday, 15 April 2014

php - Embedding Symfony controllers from other bundles -



php - Embedding Symfony controllers from other bundles -

this seems interesting issue, , i'm not sure if i'm missing because should simple, isn't.

scenario i have 1 bundle named acmepagebundle another bundle named acmegallerybundle i want load embedded view controller using acmegallerybundle bundle template file on acmepagebundle code 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 not found'); } homecoming $this->render('acmegallerybundle:display:embed.html.twig', array( 'gallery' => $gallery, )); } } acmegallerybundle\resources\views\display\embed.html.twig <div class="gallery"> {% 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 {# ... html content #} <h2>gallery</h2> {{ render(controller('acmegallerybundle:display:embed', { 'galleryid': 123 })) }} {# rest of html content #} errors

when trying render page uses acmepagebundle:default:index.html.twig, get

an exception has been thrown during rendering of template ("class 'acmegallerybundle' not exist") in acmepagebundle:default:index.html.twig @ line 18.

but of course, acmegallerybundle in fact exist. i'm suspecting scope problem i've missed somewhere.

troubleshooting ensured acmegallerybundle loaded in appkernel.php file tried adding use acme\gallerybundle top of acmepagebundle.php bundle file. found issue on github relating problem no response devs yet. i've added own comments - may in fact bug.

am missing obvious?

my error in line:

$gallery = $this->getdoctrine()->getrepository('acmegallerybundle')->find($galleryid);

the command getrepository('acmegallerybundle') needs include entity i'm trying load repository in question. right code is:

$gallery = $this->getdoctrine()->getrepository('acmegallerybundle:gallery')->find($galleryid);

i mistakenly thought issue render(controller(...)) functionality. after fix, works should. next time should looking closer @ stack trace!

php symfony2 twig

No comments:

Post a Comment