【发布时间】:2012-02-29 14:03:15
【问题描述】:
我正在 symfony2 中创建自定义表单类型。但是每次我尝试覆盖 buildForm() 方法时,我都会收到此错误:
致命错误:SeduceMe\SiteBundle\Form\Type\UniFormTextType::buildView() 的声明必须与 /Users/alexander/Projekte/SeduceMe/ 中 Symfony\Component\Form\FormTypeInterface::buildView() 的声明兼容serversymfony204/src/SeduceMe/SiteBundle/Form/Type/UniFormTextType.php 在第 33 行
我当然明白这意味着什么。我什至从提到的接口复制了方法签名。还是一样。这是我的课:
namespace SeduceMe\SiteBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class UniFormTextType extends AbstractType
{
public function getDefaultOptions(array $options)
{
return array('placeholder' => null);
}
public function getParent(array $options)
{
return 'text';
}
public function getName()
{
return 'UniFormText';
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder->setAttribute('placeholder', $options['placeholder']);
}
public function buildView(FormView $view, FormInterface $form)
{
$view->set('placeholder', $form->getAttribute('placeholder'));
}
}
【问题讨论】: