В моей форме блог у меня есть поле с авторами:Symfony 3 сохранить данные формы из организации без объединения
<?php
$this->add(
'user',
EntityType::class,
[
'label' => 'Author',
'class' => 'Hitso\Bundle\CommonBundle\Entity\User',
'placeholder' => 'Select post author',
'mapped' => false,
'empty_data' => null,
]
)
Но в моем блоге сущности я не имею пользователь ассоциации с таблицей пользователей, у меня есть это в другой таблице - '' blogs_users:
<?php
/**
* Blog
*
* @ORM\Table(name="blogs")
* @ORM\Entity(repositoryClass="Repository\BlogRepository")
* @codeCoverageIgnore
*/
class Blog
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer", length=10, options={"unsigned"=true})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Slug(fields={"title"})
*/
private $slug;
}
И мой BlogUser объект класса:
<?php
/**
* BlogUsers
*
* @ORM\Table(name="blogs_users")
* @ORM\Entity(repositoryClass="BlogBundle\Repository\BlogUserRepository")
* @codeCoverageIgnore
*/
class BlogUser implements SiteIdAwareInterface
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="BlogBundle\Entity\Blog")
* @ORM\JoinColumn(onDelete="CASCADE")
* @var \Hitso\Bundle\BlogBundle\Entity\Blog
*/
private $blog;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="BlogBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
* @var CommonBundle\Entity\User
*/
private $user;
}
И мой BlogController :: newAction:
<?php
public function newAction(Request $request)
{
$blog = new Blog();
$form = $this->createForm(
BlogType::class,
$blog
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$blogUser = new BlogUser();
$em->persist($blogUser);
$em->persist($blog);
$em->flush();
return $this->redirectToRoute('...');
}
Но сейчас вэнь я отправить форму у меня есть ошибка ниже:
пользователь недвижимости не существует в классе BlogBundle \ Entity \ Блог
Помощь пожалуйста!
Нет, это не поможет. Это была моя ошибка. –