我的應用北京時間運行,但是當我使用自定義表單,字段類型(shtumi_daterange),如:如何在Silex/Twig中註冊自定義表單字段類型?
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$dateRange4 = new DateRange('m/d/Y');
$dateRange4->parseData('03/27/2012 - 04/05/2012');
$builder->add('builddate', "shtumi_daterange", array('required'=>false, 'default'=>$dateRange4));
}
在出現此錯誤:
Uncaught exception 'Symfony\Component\Form\Exception\FormException' with
message 'Could not load type "shtumi_daterange"' in
../vendor/symfony/form/Symfony/Component/Form/FormRegistry.php:95
我想,我需要的是這樣的:
<?php
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => $path_ext_dir_abs . '/views',
'twig.form.templates' => array('form_div_layout_custom.html.twig'),
'form.type.shtumi_daterange' => 'Shtumi\UsefulBundle\Form\Type\DateRangeType',
));
但我只是不知道/找到正確的symtax!
從symfony documentation,我發現這個例子如何註冊自定義表單字段類型,但我不能改變這個把它與硅石運行:
services:
form.type.gender:
class: Acme\DemoBundle\Form\Type\GenderType
arguments:
- "%genders%"
tags:
- { name: form.type, alias: gender }
謝謝 - 我喜歡這甚至比使用字符串更多。 – Benjamin 2012-08-17 17:15:29