簡體   English   中英

不用樹枝即可使用Silex FormServiceProvider

[英]Using Silex FormServiceProvider without twig

如何在不使用樹枝的情況下渲染使用Silex FormServiceProvider構建的FormServiceProvider

我嘗試了$form$form->createView() ,也查看了Form和FormView的API文檔,但我不知道該怎么做。

這是我的代碼:

$app->get('/form', function (Request $request) use ($app) {
    // some default data for when the form is displayed the first time
    $data = array(
        'name' => 'Your name',
        'email' => 'Your email',
    );

    $form = $app['form.factory']->createBuilder(FormType::class, $data)
       ->add('name')
       ->add('email')
       ->add('billing_plan', ChoiceType::class, array(
           'choices' => array(
               1 => 'free', 
               2 => 'small_business', 
               3 => 'corporate'
            ),
            'expanded' => true,
       ))
       ->getForm();

    $form->handleRequest($request);

    // I want return the form here
    return 'ok';
});

您是否嘗試過此方法: http : //symfony.com/doc/2.3/book/forms.html#rendering-the-form

$formView = $form->createView();
$html = $formView->start($form) .
$formView->widget($form) .
$formView->end($form);

說實話,我沒有時間去檢查,但這可能會有所幫助。

暫無
暫無

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

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