English 中文(简体)
从提交表格到Syfmony2特定路线的通过参数
原标题:Pass parameters from form submission to specified route in Syfmony2
  • 时间:2011-10-03 08:23:36
  •  标签:
  • symfony

我有一条路线。 摘录如下:

pattern:  /admin/clients/{clientid}/projects/{projectid}/review/{id}/comments
defaults: { _controller: ShoutAdminBundle:Project:revcomm }
requirements:
    _method:  POST

现在,在一页(评论页)上,我有一份表格,用户将提出意见,然后提交该网页。 然后,用户点击提交,将回首页,但其评论将提交给数据库,然后展示。

My Form code looks like this:

        <form action="{{ path( ShoutAdminBundle_adminprojectreviewcommentssuccess ) }}" method="post" {{ form_enctype(form) }} class="blogger">
            {{ form_errors(form) }}

            <p class="comments">
                {{ form_label(form.from,  Your Name* , {  attr : { class :  title } }) }}
                {{ form_errors(form.from) }}
                {{ form_widget(form.from, {  attr : { class :  textfield }}) }}
            </p>
            <p class="comments">
                {{ form_label(form.comment,  Your Comment* , {  attr : { class :  title } }) }}
                {{ form_errors(form.comment) }}
                {{ form_widget(form.comment, {  attr : { class :  textfield }}) }}
            </p>
            <p class="comments_save">
                <input type="submit" value="Post Your Comment" id="savebutton" class="savebutton" />
            </p>
            {{ form_rest(form) }} 
        </form>

现在。 当该网页被贴上时,我有以下错误:

An exception has been thrown during the rendering of a template ("The "ShoutAdminBundle_route" route has some missing mandatory parameters ("id", "projectid").") in "ShoutAdminBundle:Default:projectreviewcomments.html.twig" at line 54.

我如何将各种变量({clientid},{projectid}{id}上移至网页? 这些变量已在网页上公布,这提出了一个问题,即我如何在形式上列入这些变量?

Cheers

最佳回答

您可通过您的管理人员通过联系阵列通过:

class ProjectController extends Controller
{
    public function revcommAction($clientid, $projectid, $id)
    {
        // ...

        $params = array(
             clientid   => $clientid,
             projectid  => $projectid,
             id         => $id
        );
        return $this->render( ShoutAdminBundle:Default:projectreviewcomments.html.twig , $params);
    }
}

为了在模板中向该控制员提供一种链接(或形式行动的道路),您可使用<代码>path(<>/code>作为相对链接和url(<>)为绝对链接。 第二项论点涉及建立这一联系所需的任何论点,例如:

<a href="{{ path( my_route_name , { clientid : clientid, ...}) }}"></a>
问题回答

暂无回答




相关问题
Symfony 5, I can t start the server

I develop a symfony project and everything was fine. But since yesterday I can not launch the server: enter image description here The commands symfony server:start and symfony server:stop don t work ...

learning symfony 1.4 will be good when using symfony 2.0?

I know that the architecture is different in symfony 2.0 but im learning 1.4 right now. I wonder if this knowledge i gain about 1.4 will be usable for 2.0 in some extent or will it be a total waste ...

Is symfony 2.0 stable enough to use? [closed]

I wonder if Symfony 2.0 is stable enough to use? Because I ve never used Symfony before. It seems that Symfony 2 is much better than the previous version and I don t want to relearn/recode ...

your experience using symfony 2.0 [closed]

I m going to start a new project that s building web apps from scratch. I have been thinking about using symfony framework for this project. Should I start using symfony 2.0 or stick with 1.4 ? I ...

How to increase the session timeout in Symfony

I would like to know how to increase the session timeout in symfony. Is it enough to only adjust the symfony configuration settings or must I also configure anything in my php.ini file?

How stable or unstable is symfony 2.0? [closed]

Well, I know it s a preview, and I know it says that it s not yet ready for production, and yet I dare ask the question. I need to start building a pretty big application, which is planned to go live ...

热门标签