Stephen Senkomago Musoke
Stephen Senkomago Musoke

Reputation: 3523

Automatically Render Symfony2 Templates for Controller Actions like Zend Framework

I am coming from a Zend Framework background, and the process for creating a page is:

  1. Create a controller
  2. Create an empty action
  3. Create a folder for the controller
  4. Create a file matching the name of the controller action and place it in the directory for the controller

When you access the application via http://host/controller/action the view file is automatically rendered.

Is it possible for me to do this within Symfony2 so that I do not have to create routing entries for each controller/action? and automatically render the twig templates for each action?

Thanks in advance

Upvotes: 0

Views: 640

Answers (1)

Bártfai Tamás
Bártfai Tamás

Reputation: 2464

You can use the @Template annotation from the SensioFrameworkExtraBundle.

 class MyController extends Controller {
     /**
      * @Template()
      */
    public function myAction() { 
        return array(); 
    }
 }

The template is Resources/views/My/my.twig.html. Note that you have to return something in the action method.

Upvotes: 1

Related Questions