我正在研究一个symfony项目。我正在与一个不会重定向到自己页面的表单进行争夺。 action属性设置为“”,方法设置为post。在这种情况下,它应该调用相同的页面,但我将以404页面结束。
以下是操作文件中我的页面代码:
public function executeDetail(sfWebRequest $ request) {
if($request->isMethod(sfRequest::POST))
{
if(!$this->getUser()->isAuthenticated())
$this->redirect('@user_login');
$formData = $request->getParameter($this->form->getName());
$this->form->bind($formData, $request->getFiles($this->form->getName()));
if ($this->form->isValid())
{
$user = $this->getUser()->getLogged();
$comment = $this->form->save();
$comment->setIsActive(1);
$comment->setAuthor($user);
$comment->setHash(md5(uniqid(rand(), true)));
$comment->setArticle($this->detail);
$comment->save();
$this->status = 'SUCCESS';
}
else
{
$this->status = 'ERROR';
}
}
$this->story = $this->getRoute()->getObject();
$this->status = false;
$this->bAuthorLogged = false;
$this->form = new ArticleCommentForm();
}
有趣的是,当我从它的网址调用页面时,它正确显示,404只有在提交表单时才会发生。
提前致谢
PS:路由配置是:
stories_detail:
url: /stories-of-the-month/:slug
class: sfDoctrineRoute
param: { module: stories, action: detail}
options: { model: Article, type: object, method: doSelectForSlug }
答案 0 :(得分:2)
您需要明确允许路由的POST。将您的路线更改为:
stories_detail:
url: /stories-of-the-month/:slug
class: sfDoctrineRoute
param: { module: stories, action: detail}
options: { model: Article, type: object, method: doSelectForSlug }
requirements:
sf_method: [get, post]