我正在从事 symfony 项目。我正在与一个不会重定向到自己页面的表单作斗争。 action 属性设置为“”,method 设置为 post。在这种情况下,它应该调用同一页面,但我会以 404 页面结束。
这是我的页面在操作文件中的代码:
公共函数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();
}
有趣的是,当我从 url 调用页面时,它会正确显示,404 仅在使用表单提交时才会发生。
提前致谢
PS:路由配置是:
stories_detail:
url: /stories-of-the-month/:slug
class: sfDoctrineRoute
param: { module: stories, action: detail}
options: { model: Article, type: object, method: doSelectForSlug }
您需要明确允许路由 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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)