Symfony Actions Namespacing, or a better way?
In Rails, you can organize controllers into folders and keep your structure nice with namespacing. I'm looking for a similar organizational structure in Symfony 1.4.
I was thinking of organizing multiple actions.class.php files in an actions folder, but all I came across was using independent action files, one for each action... like this:
# fooAction.class.php
class fooAction extends sfActions {
public function exe开发者_如何学JAVAcuteFoo() {
echo 'foo!';
}
}
But I'd have to develop a whole new routing system in order to fit multiple actions into that file, which is... silly.
Really I'm just looking to make Symfony into Rails, (again, silly, but I'm stuck with Symfony for this project) so I'm wondering if there's a better way....?
Thanks.
An alternative action syntax is available to dispatch the actions in separate files, one file per action. In this case, each action class extends sfAction (instead of sfActions) and is named actionNameAction. The actual action method is simply named execute.
class indexAction extends sfAction
{
public function execute($request)
{
// ...
}
}
A Gentle Introduction to symfony - chapter 06: Inside the controller layer, subsection Alternative Action Class Syntax
精彩评论