Form requested url not found

99封情书 提交于 2020-01-07 02:21:23

问题


hello
Im working on a symfony project.
Im battleling with a form that wont 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 im ending on a 404 page.
here's the code of my page in the action file:

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();
    } 

what is funny is when i call the page from it's url it's correctly show up, 404 only appens when submiting with the form.
i hope this speaks to somebody
thx in advance


回答1:


1) Do define your form opening tag like this in your view:

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

2) check if your route accept your http method (post/put): call from bash in your app directory:

./symfony app:routes frontend

Youll see all your routes and theres definitions (with accepted http methods)

3) you can define it in Your routing:

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]

This is very good info source about configs: http://www.symfony-project.org/reference/1_4/en/



来源:https://stackoverflow.com/questions/8699173/form-requested-url-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!