我在me\mybundle\resources\config\routing.yml添加了以下路由:
my_homepage: pattern: / defaults: { _controller: memybundle:default:index }
bundle controller
namespace me\mybundle\controller;use symfony\bundle\frameworkbundle\controller\controller;class defaultcontroller extends controller{ public function indexaction() { $form = $this->createformbuilder() ->getform() ; return $this->render('memybundle::index.html.twig', array( 'form' => $form->createview(), 'param1' => 'some_string_1', 'param2' => 'another string', )); }}
我想要在同一个form表单里创建可以重复利用的自定义的form字段,以下是利用代码
public function indexaction() { $paramsarr_1 = array( 'param1' => 'some_string_1', 'param2' => 'another string', ); $paramsarr_2 = array( 'param1' => 'some_string_2', 'param2' => 'another fine string', ); $form = $this->createformbuilder() ->add(mycustomfield, $paramsarr_1) ->add(mycustomfield_2, $paramsarr_2) ->getform() ; return $this->render('memybundle::index.html.twig', array( 'form' => $form->createview() )); }
参考了官方文档,但是还是不会,有谁知道吗?
回复内容: 我在me\mybundle\resources\config\routing.yml添加了以下路由:
my_homepage: pattern: / defaults: { _controller: memybundle:default:index }
bundle controller
namespace me\mybundle\controller;use symfony\bundle\frameworkbundle\controller\controller;class defaultcontroller extends controller{ public function indexaction() { $form = $this->createformbuilder() ->getform() ; return $this->render('memybundle::index.html.twig', array( 'form' => $form->createview(), 'param1' => 'some_string_1', 'param2' => 'another string', )); }}
我想要在同一个form表单里创建可以重复利用的自定义的form字段,以下是利用代码
public function indexaction() { $paramsarr_1 = array( 'param1' => 'some_string_1', 'param2' => 'another string', ); $paramsarr_2 = array( 'param1' => 'some_string_2', 'param2' => 'another fine string', ); $form = $this->createformbuilder() ->add(mycustomfield, $paramsarr_1) ->add(mycustomfield_2, $paramsarr_2) ->getform() ; return $this->render('memybundle::index.html.twig', array( 'form' => $form->createview() )); }
参考了官方文档,但是还是不会,有谁知道吗?