2017-07-07 78 views
0

我有我的數據庫插件數據的問題。預期類型的​​參數「的appbundle 實體 MYMACHINE或空」,「整數」給出

我有錯誤

Expected argument of type "AppBundle\Entity\VoiceAnswerMachine or null", "integer" given 

我的實體之一

/** 
* @ORM\GeneratedValue(strategy="AUTO") 
* @ORM\Id 
* @ORM\Column(type="integer") 
*/ 
private $id; 

/** 
* @ORM\ManyToOne(targetEntity="VoiceAnsweringMachine", inversedBy="uid") 
*/ 
protected $uid; 

/** 
* @ORM\Column(type="integer", nullable=true) 
*/ 
private $buttonNumber; 

/** 
* @ORM\Column(type="text", nullable=false) 
*/ 
private $linkToMusic; 

..... getters, setters 


/** 
* Set uid 
* 
* @param \AppBundle\Entity\VoiceAnswerMachine $uid 
* 
* @return AnsweringMachine 
*/ 
public function setUid(\AppBundle\Entity\VoiceAnswerMachine $uid = null) 
{ 
    $this->uid = $uid; 

    return $this; 
} 

/** 
* Get uid 
* 
* @return \AppBundle\Entity\VoiceAnswerMachine 
*/ 
public function getUid() 
{ 
    return $this->uid; 
} 

我的實體兩個

/** 
* @ORM\GeneratedValue(strategy="AUTO") 
* @ORM\Id 
* @ORM\Column(type="integer") 
*/ 
private $id; 

/** 
* @ORM\OneToMany(targetEntity="AnsweringMachine", mappedBy="uid") 
*/ 
private $uid; 

/** 
* @ORM\Column(type="integer") 
*/ 
private $numberMachine; 

/** 
* @ORM\Column(type="string") 
*/ 
private $nameMachine; 

/** 
* @ORM\Column(type="text") 
*/ 
private $linkToVoice; 

/** 
* Constructor 
*/ 
public function __construct() 
{ 
    $this->uid = new \Doctrine\Common\Collections\ArrayCollection(); 
} 

/** 
* Get id 
* 
* @return integer 
*/ 
public function getId() 
{ 
    return $this->id; 
} 

/** 
* Set numberMachine 
* 
* @param integer $numberMachine 
* 
* @return VoiceAnsweringMachine 
*/ 
public function setNumberMachine($numberMachine) 
{ 
    $this->numberMachine = $numberMachine; 

    return $this; 
} 

/** 
* Get numberMachine 
* 
* @return integer 
*/ 
public function getNumberMachine() 
{ 
    return $this->numberMachine; 
} 

/** 
* Set nameMachine 
* 
* @param string $nameMachine 
* 
* @return VoiceAnsweringMachine 
*/ 
public function setNameMachine($nameMachine) 
{ 
    $this->nameMachine = $nameMachine; 

    return $this; 
} 

/** 
* Get nameMachine 
* 
* @return string 
*/ 
public function getNameMachine() 
{ 
    return $this->nameMachine; 
} 

/** 
* Set linkToVoice 
* 
* @param string $linkToVoice 
* 
* @return VoiceAnsweringMachine 
*/ 
public function setLinkToVoice($linkToVoice) 
{ 
    $this->linkToVoice = $linkToVoice; 

    return $this; 
} 

/** 
* Get linkToVoice 
* 
* @return string 
*/ 
public function getLinkToVoice() 
{ 
    return $this->linkToVoice; 
} 

/** 
* Add uid 
* 
* @param \AppBundle\Entity\AnsweringMachine $uid 
* 
* @return VoiceAnsweringMachine 
*/ 
public function addUid(\AppBundle\Entity\AnsweringMachine $uid) 
{ 
    $this->uid[] = $uid; 

    return $this; 
} 

/** 
* Remove uid 
* 
* @param \AppBundle\Entity\AnsweringMachine $uid 
*/ 
public function removeUid(\AppBundle\Entity\AnsweringMachine $uid) 
{ 
    $this->uid->removeElement($uid); 
} 

/** 
* Get uid 
* 
* @return \Doctrine\Common\Collections\Collection 
*/ 
public function getUid() 
{ 
    return $this->uid; 
} 

我的枝條

<div class="row"> 
          <div class="col-sm-12"> 
           {{ form_start(answeringForm, {'attr': {'autocomplete': 'off'}}) }} 
           <div class="form-group"> 
            <div class="col-sm-12"> 
             {{ form_label(answeringForm.uid, 'Wybierz maszynę') }} 
            </div> 
            <div class="col-sm-12" style="margin-bottom: 15px;"> 
             {{ form_errors(answeringForm.uid) }} 
             {{ form_widget(answeringForm.uid) }} 
            </div> 
           </div> 
           <div class="form-group"> 
            <div class="col-sm-12"> 
             {{ form_label(answeringForm.buttonNumber, 'Numer przycisku do przekierowania') }} 
            </div> 
            <div class="col-sm-12" style="margin-bottom: 15px;"> 
             {{ form_errors(answeringForm.buttonNumber) }} 
             {{ form_widget(answeringForm.buttonNumber) }} 
            </div> 
           </div> 
etc ..... 

我的構建形式

public function buildForm(FormBuilderInterface $builder, array $options) { 
    $builder->add('uid', ChoiceType::class, array(
        'choices' => array('Dla dzwoniących' => 1, 'Oddzwaniająca' => 2), 
        'required' => false, 
        'label' => 'Wybierz maszynę', 
      )) 
      ->add('buttonNumber', ChoiceType::class, array(
        'choices' => array('1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9), 
        'required' => false, 
        'label' => 'Numer przycisku' 
      )) 
      ->add('linkToMusic', TextType::class, [ 
       'label' => 'Adres URL do muzyki', 
       'required' => true 
      ]) 
      ->add('telephoneNumber', PhoneNumberType::class, [ 
       'label' => 'Numer Telefonu', 
       'required' => false, 
       'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE, 
       'preferred_country_choices' => ['PL'] 
      ]) 
      ->add('acceptRegulations', ChoiceType::class, array(
        'choices' => array('1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9), 
        'required' => false, 
        'label' => 'Numer przycisku do akceptacji regulaminu' 
      )) 
      ->add('submit', \Symfony\Component\Form\Extension\Core\Type\SubmitType::class, array(
       'label' => 'Zapisz' 
      )); 
} 

我已經加入$buttoNumber$linkToMusic等,但我沒有加入$uid 我想清楚我的緩存,但我不知道我有一個問題。幫幫我吧:)

+0

代碼taht在數據庫中添加數據(如表單類型爲例)將是有益的 –

+0

我具體化我的帖子:) –

+0

'公共職能的setuid(\的appbundle \實體\ VoiceAnswerMachine $ UID = NULL)'被稱爲一個整數。確保不從框架的自動行爲。 –

回答

3
'choices' => array('Dla dzwoniących' => 1, 'Oddzwaniająca' => 2), 

您的整數關口,但你需要傳遞類型的實體VoiceAnswerMachine

+0

當然是肯定的,但我不知道通過類型VoiceAnswerMachine的實體? –

+0

那麼你真的需要閱讀的Symfony文檔有關的EntityType https://symfony.com/doc/current/reference/forms/types/entity.html –

+0

你能把它作爲解決嗎? –

相關問題