簡體   English   中英

symfony 2創建自定義表單如何獲取表單自定義元素?

[英]symfony 2 create custom form how to get form custom element?

$form = $this->createForm(new OrganizationType(), $entity, array(
        'action' => $this->generateUrl('_control_organization_create'),
        'method' => 'POST',
    ));

    $form->add('submit', 'submit', array('label' => 'Create'));

    return $form;

有定義的動作和方法。 怎么得到這個? 在模板引擎樹枝成自定義渲染?

通過致電,

{{ form(form) }}

要么,

{{ form_start(form) }}

使用添加到表單定義中的actionmethod選項值。

從文檔中...

另外,請查看文檔的“ 構建表單”部分 ,以了解如何通過傳遞HTML表單

array('form' => $form->createView()) 

到控制器中的渲染助手。

然后,看一下同一文檔的“ 渲染表單”部分

還...

如果您想在模板中覆蓋它們,則必須按照以下步驟將正確的值傳遞給form()form_start()幫助器,

{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}

{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
Return your form like this

return $this->render('Your Bundle name: Your controller name : Your twig file', array(
            'form' => $form->createView(),
        ));


And in your twig file get the form like this:

{{ form(form) }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM