2012-07-03 27 views
0

相兼容我試圖爲我的Symfony2窗體實現一個自定義字段類型,但無論出於何種原因我得到一個致命的在這個問題的標題中說錯誤。
我已經複製從接口正本報關,但無濟於事:-(:: buildView()必須與Symfony Component Form FormTypeInterface :: buildView()

<?php 
namespace Yanic\HomeBundle\Form\Type; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilder; 
use Symfony\Component\Form\FormView; 
use Symfony\Component\Form\FormInterface; 
use Symfony\Component\Form\FormError; 
use Symfony\Component\Form\CallbackValidator; 
use Symfony\Component\Form\FormValidatorInterface; 

class ShowOnlyType extends AbstractType 
{ 
/** 
    * {@inheritdoc} 
    */ 
    function buildView(FormViewInterface $view, FormInterface $form, array $options) 
    { 
     $view->addVars(array(
      'value' => date('d/m/Y H:i', $options['value']) 
     )); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setDefaultOptions(OptionsResolverInterface $resolver) 
    { 

     $resolver->setDefaults(array(
       'data_class' => 'DateTime' 
     )); 
    } 

    public function getParent() 
    { 
     return 'form'; 
    } 

    public function getName() 
    { 
     return 'showOnly'; 
    } 
} 

感謝所有幫助

回答

7

這裏是an answer應該解決您的問題。

原因最有可能的是你沒有use所需的參數類型。

use Symfony\Component\Form\AbstractType, 
use Symfony\Component\Form\FormViewInterface; 
use Symfony\Component\Form\FormInterface; 

//... 
class SomeType extends AbstractType 
{ 
    public function buildView(FormViewInterface $view, FormInterface $form, array $options) 
} 
+0

喜馬可,FormViewInterface做訣竅。那個沒有出現在你已經試過的答案中。非常感謝 :-) – Michi

相關問題