Ask your Symfony questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Module and action not in request when submitting a form Symfony



I have quite a strange problem with a Symfony 1.4 project that I haven't been able to solve after doing lots of research and debugging. I think it is something small that I am missing cause I did stuff like this a million times before without a problem. I have a page called storySingle, this page has a form where users can leave a comment.
// storySingleSuccess.php
<form action="<?php echo url_for('@user_story?title='.$story->getSlug()) ?>" method="post">
<?php echo $form ?>
<input type="submit" value='Reactie plaatsen'/>

The form will submit to itself and saving the form information is handled in the action:
class profileActions extends sfActions


public function executeStorySingle(sfWebRequest $request)
$title = $request->getParameter('title');
$this->name = $request->getParameter('subdomain');

$this->user = Doctrine::getTable('sfGuardUser')->retrieveByUsername($this->name);
$this->story = Doctrine::getTable('Story')->retrieveByUserIdAndSlug($this->user->getId(), $title);

$options = array(
'story_id' => $this->story->getId(),
$this->form = new StoryCommentForm(null, $options);

if ($request->isMethod('post')) {
if ($this->form->isValid()) {
$comment = $this->form->save();

My routing file contains the following routes:
url: /
class: sfDomainRoute
param: { module: home, action: index }
url: /verslagen
class: sfDomainRoute
param: { module: profile, action: stories }
url: /verslag/:title
class: sfDomainRoute
param: { module: profile, action: storySingle }

In another template I have a link to a certain user_story which works fine:
<?php echo link_to($story->getTitle(), '@user_story?title='.$story->getSlug()) ?>

The problem arises when I fill in the form on the storySingle page and press submit. The following exception is thrown:
404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/verslag/title-of-story" (/).

I did put some debugging code in "lib/vendor/symfony/lib/controller/sfFrontWebController.class.php" and found out that both $moduleName and $actionName are empty because apparently they are not in the request. If I check the request ($this->context->getRequest()) it does have other parameters like the post parameters of my form.

Does anybody have a clue why the module and action are absent from the request?

Answers (3)


Francesco Tassi answers:

Try adding sf_method To ruote definition in routing.yml. If you get 404 posting To a route Maybe you a have To enable post method for that ruote. Check routing reference To get the exact syntax.

It should work.

Wouter Peschier comments:

Thanks! Adding the sf_method did indeed fix the problem :)


Sergey Kushniruk answers:

You're using sfRequestRoute which extends sfRequestRoute that requires sf_method param to be specified or defaults to GET. So you should specify sf_method param in your routing.yml like this:

url: /verslag/:title
class: sfDomainRoute
param: { module: profile, action: storySingle, sf_method: [get, post] }

Wouter Peschier comments:

Thanks! The only thing is that you have to put the sf_method as a requirement instead of as a param ;)

url: /verslag/:title
class: sfDomainRoute
param: { module: profile, action: storySingle }
requirements: { sf_method: [get, post] }


Karol Sójko answers:

Try to erase the class attribute in the routings defined