我正在symfony2中創建自定義表單類型。但每次我嘗試覆蓋buildForm()方法,我得到這個錯誤:在symfony2中創建自定義表單類型:無法覆蓋buildView()
Fatal error: Declaration of SeduceMe\SiteBundle\Form\Type\UniFormTextType::buildView() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildView() in /Users/alexander/Projekte/SeduceMe/serversymfony204/src/SeduceMe/SiteBundle/Form/Type/UniFormTextType.php on line 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'));
}
}
手動的當前版本看起來是最新的:HTTP:// symfony的。 COM/DOC /電流/電子書/ forms.html。該鏈接是2.0版,對於該版本的symfony是正確的 – wgcrouch 2012-10-21 19:23:45