[英]Symfony2 Form folder
I need to create a form class,I'm following the symfony book in http://symfony.com/doc/current/book/forms.html 我需要创建一个表单类,我正在关注http://symfony.com/doc/current/book/forms.html中的symfony书。
I am trying to create a form in src/Acme/TaskBundle/Form/Type/TaskType.php, but when I look at the folder structure on my project there is no "Form" folder. 我正在尝试在src / Acme / TaskBundle / Form / Type / TaskType.php中创建一个表单,但是当我查看项目中的文件夹结构时,没有“Form”文件夹。
I try to create the Form folder manually, in src/Acme/TaskBundle/, I get an error in the the Form Folder and in the TaskType.php files ( namespace Acme\\TaskBundle\\Form\\Type Expected:Identifier). 我尝试手动创建Form文件夹,在src / Acme / TaskBundle /中,我在表单文件夹和TaskType.php文件中遇到错误(名称空间Acme \\ TaskBundle \\ Form \\ Type Expected:Identifier)。
Is there a way to create the Form folder in an automatic way? 有没有办法以自动方式创建窗体文件夹? Or how can I create in manually?
或者我如何手动创建?
The Form
folder is just a convention — you can put your forms wherever you want. Form
文件夹只是一个约定 - 您可以将表单放在任何地方。 The convention extends to: 该公约延伸至:
Form\\Type
for form types, Form\\Type
表单类型, Form\\Model
for form models , Form\\Model
for form models , Form\\Handler
for form handlers, Form\\Handler
程序的Form\\Handler
, 你试过这个命令,可能就是你要找的东西
php app/console generate:doctrine:form
I just created it manually. 我刚刚手动创建它。 form: (my case: LL\\NameBundle\\Form)
form :(我的情况:LL \\ NameBundle \\ Form)
FormName.php FormName.php
<?php
namespace LL\NameBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class FormName extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('add')
->add('your')
->add('fields')
;
}
public function getName()
{
return 'form-name';
}
}
Controller: 控制器:
use LL\NameBundle\Form\FormName;
public function()
{
$form = new FormName();
$form = $this->form( $form, $entity );
return array(
'form' => $form->createView()
);
}
This Works for me, if it doesn't work please post some code. 这对我来说,如果它不起作用,请发布一些代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.