Hello everyone,

Personally i find it quite a step to move from controllers using base-class to 
ones using services at some point X where I already wrote a number of 
controllers:

1. I have to change the controller code
2. I have to define all the services
3. I have to change all the routes

This work load often makes me NOT move to controllers as services. However we 
should not punish people that started with the base controller. However 
controllers as services allow to abstract some common logic through all 
controllers very easily (so recommended approach).

I would like to propose a simpler approach than the "service.action" sytnax for 
using controllers as services "by convention":

A. Keep the Bundle:Controller:Action syntax in routes
B. Ship a controller util service that does the most common controller grunt 
work (example: https://gist.github.com/1042220, essentially just copyed the 
methods from Controller)

This would help to simplify point 1 alot and get rid of point 3 entirely.

Example:

the "_controller: WhitewashingBlogBundle:Post:list" key would be used to check 
for $container->has("whitewashing_blog.controller.post")

The general rule would be $serviceName = slugify($bundle) . ".controller." . 
slugify($controller)

Then you can just change your controllers easily by registering in the DIC:

  whitewashing_blog.controller.post:
    arguments:
      "@controller_utils"

And "almost" find+replace all occurances of "$this->" to "$this->util->" for a 
simple controller:

  class PostController
  {
     private $util;

     public function __construct($util)
     {
        $this->util = $util;
     }

     public function listAction()
     {
        return $this->util->render("....");
     }
  }

What do you think?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to