表单请求的网址未找到

时间:2012-01-02 09:25:52

标签: post request symfony-1.4 symfony-forms

你好我正在研究一个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只在提交表单时才会出现。
我希望这可以事先向某人说话

1 个答案:

答案 0 :(得分:0)

1)在您的视图中定义您的表单开头标记:

<?php echo $form->renderFormTag($sf_request->getUri()) ?>

2)检查您的路线是否接受您的http方法(发布/放置): 在你的app目录中从bash调用:

./symfony app:routes frontend

您将看到所有路线和theres定义(使用接受的http方法)

3)您可以在路由中定义它:

route_name:
  url:        /my-nice-url
  param:    { module: yourModuleName, action: detail }
  requirements:
    # this is what matters - if you leave it undefined, it shlould accept any HTTP method
    sf_method: [get, post, put, delete]

这是关于配置的非常好的信息来源: http://www.symfony-project.org/reference/1_4/en/

相关问题