我試圖按名稱構建Symfony表單(以Silex)。使用下面的配置,我相信我應該可以調用$form = $app['form.factory']->createBuilder('address');
,但FormRegistry找不到這種類型的表單。在Silex中使用Symfony Form 2.3
$app['form.type.extensions'] = $app->share($app->extend('form.type.extensions', function($extensions) use ($app) {
$extensions[] = new AddressType();
return $extensions;
}));
有沒有別的東西,我需要做什麼或以這種方式建立的形式以不同的方式:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormTypeExtensionInterface;
class AddressType extends AbstractType implements FormTypeExtensionInterface
{
public function getName()
{
return 'address';
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('addressee', 'text');
// .. fields ..
$builder->add('country', 'text');
}
public function getExtendedType()
{
return 'form';
}
}
這然後使用form.type.extensions
提供商加入到表單註冊?
您的地址類型類是否有返回'form'的getParent()函數? – gunnx