Search code examples
symfonycontrollertwigsymfony-cmf

Symfony2 - Render controller show blank page


I started develop in symfony now and i work in a CMS with Symfony CMF, i need to create a function with some lines in php and JS to insert into in running page or a existing template.

I created a Action at main controller for this template and i try render controller inside a twig with this line:

{{ render(controller('siteCmsBundle:Article:fish')) }}

But this return a blank page, i tried also this code:

{% render 'siteCmsBundle:Article:fish' %}

This return a route error (logical).

And the controller is:

<?php

namespace site\Bundle\CmsBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Wf\Bundle\CmsBaseBundle\Controller\ArticleController as BaseArticleController;
use  Wf\Bundle\CmsBaseBundle\Entity\Collection\Module\PageCompositeEditorModule;

class ArticleController extends BaseArticleController
{

   ...

    /**
     * @Template()
     */
    public function fishAction(){

        return new Render("Test");
    }
}

Well, i'll continue to learn this framework, but i need conclude this issue today. :(

Can someone help me with this?

Thanks a lot!


Solution

  • Use annotation and just return single array.

    /**
     * @Template()
     */
    public function fishAction(){
    
        return 
            array('fish' => 'saumon');
    }
    

    OR Add to method render() who extend of Controller class the template.

    public function fishAction(){
        return $this->render(
            'siteBundle:CmsBundle:fishTemplate.html.twig',
            array('fish' => 'saumon')
        );
    }