I am working on a new project on the most recent version of Symfony 2.1.4, with PHP 5.4.7.
I went through the readme file, passed the app/check.php and the configuration, the Acme Demo is running fine, every pages tested.
Then, I added my own bundle, edited the app/AppKernl.php, and the app/routing.yml so it loads my own routing.yml from my bundle, and tested the indexAction() in my SetupController with
return $this->render('MyBundle:Setup:index.html.twig');
The page is displayed as expected.
Then I changed it to use annotation, so the Controller file became
// ...
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
// ...
class SetupController extends Controller
{
/**
* @Route("/", name="_setup")
* @Template
*/
public function indexAction(){
// This method is totally empty.
// Uncommenting the following line actually works, but I want to stick with
// annotations if possible
// return $this->render('MyBundle:Setup:index.html.twig');
}
}
And the routing file became
_setup:
resource: "@MyBundle/Controller/SetupController.php"
type: annotation
Now the page throws a 500 Internal Server Error (LogicException), with the following message:
The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
I tried adding the $this->render('...') line to the indexAction(), the page renders, but without it just this 500 error.
The Acme Demo is still running beautifully. I tried using @Template('MyBundle:Setup:index.html.twig') and @Template(), instead of @Template, the same error still occurs. The template file is placed in a correct location as the $this->render() method found it without problems.
I checked and made sure I didn’t turn off annotation in any config files. I also tried clearing the caches, both dev and prod ones, but still no luck.
I can use $this->render() as a work around, but I wanted to know what’s wrong with the annotation that Symfony won’t let me use it.
Thanks in advance for any help or advise! Please let me know if there is any other information I can provide to help.
When using the
@Templateannotation you need to return anarray()of variables that will be passed to the template.If you have no variables than just
return array()