Symfony-找不到表格要求的网址 [英] Symfony - Form requested url not found

查看:90
本文介绍了Symfony-找不到表格要求的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个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-找不到表格要求的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆