我有点问题。
我收到此错误
在AppBundle \ Entity \ User
上缺少主键ID的值
这是我的实体
/**
* @ORM\Entity
* @ORM\Table(name="caller_machine")
*/
class CallerMachine {
/**
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $buttonNumber;
/**
* @ORM\Column(type="text", nullable=false)
*/
private $linkToMusic;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $telephoneNumber;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $acceptRegulations;
/**
* @ORM\ManyToOne(
* targetEntity = "AppBundle\Entity\CallerMachineVoice"
* )
*
* @ORM\JoinColumn(
* name = "number_id",
* referencedColumnName = "id",
* nullable = false
* )
*/
private $numberMachine;
.......
/**
* @ORM\Entity
* @ORM\Table(name="user_name")
*/
class User {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length = 20, unique = true)
*/
private $username;
...........
/**
* @ORM\Entity
* @ORM\Table(name="call_back_machine")
*/
class CallBackMachine {
/**
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $buttonNumber;
/**
* @ORM\Column(type="text", nullable=false)
*/
private $linkToMusic;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $telephoneNumber;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $acceptRegulations;
/**
* @ORM\ManyToOne(
* targetEntity = "AppBundle\Entity\CallBackMachineVoice"
* )
*
* @ORM\JoinColumn(
* name = "number_id",
* referencedColumnName = "id",
* nullable = false
* )
*/
private $numberMachine;
.......
/**
* @ORM\Entity
* @ORM\Table(name="call_back_machine_voice")
*/
class CallBackMachineVoice {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(
* targetEntity = "AppBundle\Entity\User"
* )
*
* @ORM\JoinColumn(
* name = "users_id",
* referencedColumnName = "username",
* nullable = false
* )
*/
private $user;
/**
* @ORM\Column(type="string")
*/
private $linkToMusic;
...............
/**
* @ORM\Entity
* @ORM\Table(name="caller_machine_voice")
*/
class CallerMachineVoice {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToOne(
* targetEntity = "AppBundle\Entity\User"
* )
*
* @ORM\JoinColumn(
* name = "users_id",
* referencedColumnName = "username",
* nullable = false
* )
*/
private $user;
/**
* @ORM\Column(type="string")
*/
private $linkToMusic;
当我创建表单
时public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('numbermachine', EntityType::class, [
'class' => 'AppBundle\Entity\CallerMachineVoice',
'choice_label' => 'user'
])
->add('buttonnumber', IntegerType::class, [
'label' => 'Podaj numer przycisku'
])
->add('linktomusic', TextType::class,[
'label' => 'Podaj link do muzyki'
])
->add('telephonenumber', IntegerType::class, [
'label' => 'Podaj numer przycisku'
])
->add('acceptregulations', IntegerType::class, [
'label' => 'Podaj numer przycisku'
])
->add('submit', \Symfony\Component\Form\Extension\Core\Type\SubmitType::class, array(
'label' => 'Zapisz'
));
}
我有一个问题,但是当我删除行时,numberMachine''我看到了我的表格。我的问题在哪里?帮帮我:)
现实化
可能我的问题是实体CallerMachineVoice
答案 0 :(得分:1)
试试这个:
在CallerMachineVoice上:
/**
* @ORM\ManyToOne("User")
* @ORM\JoinColumn(
* name = "user_id",
* referencedColumnName = "id",
* nullable = false
* )
*/
private $user;
然后在User Entity __toString魔术方法上定义:
/**
* @return string
*/
public function __toString()
{
return $this->getUsername();
}