Symfony - Form requested url not found(Symfony - 找不到表单请求的 url)
问题描述
我正在做一个 symfony 项目.我正在与一个不会重定向到自己页面的表单作斗争.action 属性设置为",方法设置为 post.在这种情况下,它应该调用相同的页面,但我以 404 页面结束.
Im working on a symfony project. Im battleling with a form that won't redirect to its own page. The action attribute is set to "" and method set to post. In that case it should call the same page but I'm ending on a 404 page.
这是我在操作文件中的页面代码:
Here's the code of my page in the action file:
公共函数executeDetail(sfWebRequest $request){
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();
}
有趣的是,当我从它的 url 调用页面时,它正确显示,404 仅在使用表单提交时发生.
The funny thing is that when I call the page from it's url it's correctly show up, 404 only happens when submitting with the form.
提前致谢
PS:路由配置为:
stories_detail:
url: /stories-of-the-month/:slug
class: sfDoctrineRoute
param: { module: stories, action: detail}
options: { model: Article, type: object, method: doSelectForSlug }
推荐答案
您需要明确允许路由的 POST.将您的路线更改为:
You need to explicitly allow POST for the route. Change your route to:
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]
这篇关于Symfony - 找不到表单请求的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony - 找不到表单请求的 url
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01