Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony 2.1在控制器中设置窗体主题_Php_Forms_Twig_Symfony 2.1 - Fatal编程技术网

Php symfony 2.1在控制器中设置窗体主题

Php symfony 2.1在控制器中设置窗体主题,php,forms,twig,symfony-2.1,Php,Forms,Twig,Symfony 2.1,最近我在symfony 2.0中使用了symfony/Bridge/Twig/Extension/FormExtension.php中的setTheme函数,例如: $this->get('twig')->getExtension('form')->setTheme($view, $theme); sf2.1中没有此类功能。在控制器中设置窗体主题的替代方法是什么。提前感谢您的回答。我查看了Symfony 2.1的最新来源,似乎可以通过以下方式实现: $this->get

最近我在symfony 2.0中使用了symfony/Bridge/Twig/Extension/FormExtension.php中的setTheme函数,例如:

$this->get('twig')->getExtension('form')->setTheme($view, $theme);

sf2.1中没有此类功能。在控制器中设置窗体主题的替代方法是什么。提前感谢您的回答。

我查看了Symfony 2.1的最新来源,似乎可以通过以下方式实现:

$this->get('twig')->getExtension('form')->renderer->setTheme($view, $theme);

我查看了Symfony 2.1的最新来源,似乎可以通过以下方式实现:

$this->get('twig')->getExtension('form')->renderer->setTheme($view, $theme);

下面是一个完整的例子,从控制器生成带有参数的模板并为其设置主题

//使用$this->createForm()创建表单。。。
$myView=$myform->createView();
//设置窗体主题
$this->get('twig')->getExtension('form')->renderer->setTheme($myView,'XBundle:path/to/theme/myTheme.html.twig');
$content=$this->renderView('XBundle:path/to/template/myTemplate.html.twig',数组('templateParam1'=>$myView,'templateParam2'=>$param2));
返回新的响应($content);
希望这有帮助。
干杯

这里有一个完整的示例,可以从控制器生成带有参数的模板并为其设置主题

//使用$this->createForm()创建表单。。。
$myView=$myform->createView();
//设置窗体主题
$this->get('twig')->getExtension('form')->renderer->setTheme($myView,'XBundle:path/to/theme/myTheme.html.twig');
$content=$this->renderView('XBundle:path/to/template/myTemplate.html.twig',数组('templateParam1'=>$myView,'templateParam2'=>$param2));
返回新的响应($content);
希望这有帮助。 干杯