找不到表单请求的 url [英] Form requested url not found

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

问题描述

你好
我正在处理一个 symfony 项目.
我正在与一个不会重定向到自己页面的表单作斗争.action 属性设置为",方法设置为 post.在这种情况下,它应该调用相同的页面,但我以 404 页面结束.
这是我的页面在操作文件中的代码:

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

有趣的是,当我从它的 url 调用页面时,它会正确显示,404 仅在使用表单提交时才会出现.
我希望这能与某人交谈
thx 提前

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) 检查您的路由是否接受您的 http 方法(post/put):从应用程序目录中的 bash 调用:

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

./symfony app:routes frontend

你会看到你所有的路由和定义(使用接受的 http 方法)

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

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

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]

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

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

这篇关于找不到表单请求的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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