Итак, я делаю форму для сохранения атрибута, и этот атрибут должен быть ссылкой на веб-сайт. Когда я пытаюсь сохранить атрибут, я получаю эту ошибку: указан ожидаемый аргумент типа «App \ Entity \ Website», «Doctrine \ Common \ Collections \ ArrayCollection».
Вот код для 2 объекта и контроллера.
Website.php
<?php
namespace App\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\WebsiteRepository")
*/
class Website
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @var \DateTime $created_at
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @var \DateTime $updated_at
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated_at;
/**
* @var \DateTime $contentChanged
*
* @ORM\Column(name="content_changed", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="change", field={"slug", "name"})
*/
private $contentChanged;
public function __construct() {
$this->attribute = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getContentChanged()
{
return $this->contentChanged;
}
public function __toString()
{
return ($this->getName()) ? $this->getName() : '';
}
}
Attribute.php
namespace App\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AttributeRepository")
*/
class Attribute
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* Many Attibute have Many Website.
* @ORM\ManyToMany(targetEntity="Attribute")
* @ORM\JoinTable(name="attribute_website",
* joinColumns={@ORM\JoinColumn(name="attribute_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="website_id", referencedColumnName="id")}
* )
*/
private $website;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $type;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $is_master_attribute;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $options;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $prefix;
/**
* @var \DateTime $created_at
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @var \DateTime $updated_at
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated_at;
/**
* @var \DateTime $contentChanged
*
* @ORM\Column(name="content_changed", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="change", field={"slug", "name", "type", "is_master_attribute", "options", "prefix"})
*/
private $contentChanged;
public function getId(): ?int
{
return $this->id;
}
public function getWebsite(): ?Website
{
return $this->website;
}
public function setWebsite(Website $website): self
{
$this->website = $website;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getIsMasterAttribute(): ?int
{
return $this->is_master_attribute;
}
public function setIsMasterAttribute(?int $is_master_attribute): self
{
$this->is_master_attribute = $is_master_attribute;
return $this;
}
public function getOptions(): ?string
{
return $this->options;
}
public function setOptions(?string $options): self
{
$this->options = $options;
return $this;
}
public function getPrefix(): ?string
{
return $this->prefix;
}
public function setPrefix(?string $prefix): self
{
$this->prefix = $prefix;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getContentChanged()
{
return $this->contentChanged;
}
public function __toString()
{
return ($this->getName()) ? $this->getName() : '';
}
}
AttributeAdmin.php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Entity\Website;
class AttributeAdmin extends AbstractAdmin
{
private $attribute;
//public function __construct(Attribute $attribute){
//parent::__construct();
//$this->attribute = $attribute;
//}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('slug', TextType::class);
$formMapper->add('name', TextType::class);
$formMapper->add('website', EntityType::class, array(
'class' => 'App\Entity\Website',
'multiple' => true)
);
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('slug');
$datagridMapper->add('name');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('slug');
$listMapper->addIdentifier('name');
$listMapper->add('created_at', 'datetime', array('format' => 'Y-m-d H:m:s'));
$listMapper->add('updated_at','datetime', array('format' => 'Y-m-d H:m:s'));
}
}
Что я должен сделать, чтобы сохранить атрибут с веб-сайтами, которые были выбраны?
Спасибо