2

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!

diegoos
  • 86
  • 11
  • 1
    If your action is called `myAction`, you should do this : `{{ render(controller('CmsBundle:Article:my')) }}` (remove the `Action` suffix). Anyway, a blank page often means a server side error (500 error). So you should have errors in your logs (either symfony or apache) – Brewal Oct 16 '15 at 14:44
  • Hello, sorry i edited the post now. myAction was an exemple. – diegoos Oct 16 '15 at 14:52
  • 1
    `return new Render("Test");` ? Try: `return new Response("Test");` – scoolnico Oct 16 '15 at 14:54
  • Man! It's working!! But, i need add this line `use Symfony\Component\HttpFoundation\Response;` – diegoos Oct 16 '15 at 15:03
  • Thanks a lot! Brewal and scoolnico :) – diegoos Oct 16 '15 at 15:04
  • try {{ render(path('route_to_your_controller')) }} – Besbes Riadh Oct 16 '15 at 15:34
  • Thanks Besbes. I'll try later. – diegoos Oct 16 '15 at 18:46
  • look at the app/logs/prod.log or app/logs/dev.log files (depending on whether you go to app_dev.php or not) to see if you find a error message after calling the page. if not, look into the webserver logfile (apache, nginx or whatever you use). – dbu Oct 17 '15 at 14:58

1 Answers1

2

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')
    );
}
rommct
  • 228
  • 1
  • 7
  • Hi. I tried to use this options, but return "Page not found". – diegoos Oct 16 '15 at 15:11
  • Add customize template 'siteBundleCmsBundle:Fish:fishTemplate.html.twig', into site\Bundle\CmsBBundle\Resources\views\Fish\fishTemplate.html.twig – rommct Oct 16 '15 at 15:16
  • rommct, it's works! Thanks. But, the script tag doesn't work when i render controller with only – diegoos Oct 16 '15 at 18:48