我在尝试加载页面时收到此错误(Symfony 3.3):
捕获致命错误:传递给Doctrine \ Common \ Collections \ ArrayCollection :: __ construct()的参数1必须是类型数组,对象是给定的。
我查看了很多网站,但没有一个能够解决我的问题。
以下是我的实体的示例:
<?php
namespace PressferBundle\Entity\Pressfer;
use Doctrine\ORM\Mapping as ORM;
/**
* Setting
*
* @ORM\Table(name="pressfer_setting")
* @ORM\Entity(repositoryClass="PressferBundle\Repository\Pressfer\SettingRepositor
y")
*/
class Setting
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORM\Column(name="value", type="boolean")
*/
private $value;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Config",
mappedBy="Setting")
*
*/
private $config;
/**
* @ORM\ManyToOne(targetEntity="PressferBundle\Entity\Company\Company",
inversedBy="settings")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id",
onDelete="CASCADE")
*/
private $company;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Setting
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* @param boolean $value
*
* @return Setting
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return bool
*/
public function getValue()
{
return $this->value;
}
/**
* Set config
*
* @param string $config
*
* @return Setting
*/
public function setConfig($config)
{
$this->config = $config;
return $this;
}
/**
* Get config
*
* @return string
*/
public function getConfig()
{
return $this->config;
}
/**
* Set company
*
* @param string $company
*
* @return Setting
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* Constructor
*/
public function __construct()
{
$this->config = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add config
*
* @param \PressferBundle\Entity\Pressfer\Config $config
*
* @return Setting
*/
public function addConfig(\PressferBundle\Entity\Pressfer\Config $config)
{
$this->config[] = $config;
return $this;
}
/**
* Remove config
*
* @param \PressferBundle\Entity\Pressfer\Config $config
*/
public function removeConfig(\PressferBundle\Entity\Pressfer\Config
$config)
{
$this->config->removeElement($config);
}
}
<?php
namespace PressferBundle\Entity\Company;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="pf_companies")
*/
class Company
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", nullable=false)
*/
private $subdomain;
/**
* @ORM\ManyToOne(targetEntity="CompanyInfo")
* @ORM\JoinColumn(name="infoId", referencedColumnName="id", onDelete="CASCADE")
*/
private $infoid;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Setting", mappedBy="company", cascade={"persist","remove"})
*/
private $settings;
/**
* @return mixed
*/
public function getInfoId()
{
return $this->infoid;
}
/**
* @param mixed $infoId
*/
public function setInfoId($infoid)
{
$this->infoid = $infoid;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @param mixed $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getSubdomain()
{
return $this->subdomain;
}
/**
* @param mixed $subdomain
*/
public function setSubdomain($subdomain)
{
$this->subdomain = $subdomain;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* Constructor
*/
public function __construct()
{
$this->settings = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*
* @return Company
*/
public function addSetting(\PressferBundle\Entity\Pressfer\Setting $setting)
{
$this->settings[] = $setting;
return $this;
}
/**
* Remove setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*/
public function removeSetting(\PressferBundle\Entity\Pressfer\Setting $setting)
{
$this->settings->removeElement($setting);
}
/**
* Get settings
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSettings()
{
return $this->settings;
}
}
<?php
namespace PressferBundle\Entity\Pressfer;
use Doctrine\ORM\Mapping as ORM;
/**
* Config
*
* @ORM\Table(name="pressfer_config")
*@ORM\Entity(repositoryClass="PressferBundle\Repository\Pressfer\ConfigRepository")
*/
class Config
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORM\Column(name="value", type="boolean")
*/
private $value;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Config", mappedBy="dependency")
*/
private $dependency;
/**
* @ORM\ManyToOne(targetEntity="PressferBundle\Entity\Pressfer\Setting", inversedBy="config")
*/
private $Setting;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Config
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* @param boolean $value
*
* @return Config
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return bool
*/
public function getValue()
{
return $this->value;
}
/**
* Set dependency
*
* @param string $dependency
*
* @return Config
*/
public function setDependency($dependency)
{
$this->dependency = $dependency;
return $this;
}
/**
* Get dependency
*
* @return string
*/
public function getDependency()
{
return $this->dependency;
}
/**
* Constructor
*/
public function __construct()
{
$this->dependency = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add dependency
*
* @param \PressferBundle\Entity\Pressfer\Config $dependency
*
* @return Config
*/
public function addDependency(\PressferBundle\Entity\Pressfer\Config $dependency)
{
$this->dependency[] = $dependency;
return $this;
}
/**
* Remove dependency
*
* @param \PressferBundle\Entity\Pressfer\Config $dependency
*/
public function removeDependency(\PressferBundle\Entity\Pressfer\Config $dependency)
{
$this->dependency->removeElement($dependency);
}
/**
* Set setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*
* @return Config
*/
public function setSetting(\PressferBundle\Entity\Pressfer\Setting $setting = null)
{
$this->Setting = $setting;
return $this;
}
/**
* Get setting
*
* @return \PressferBundle\Entity\Pressfer\Setting
*/
public function getSetting()
{
return $this->Setting;
}
}
答案 0 :(得分:1)
正如我所料,这是一个非常小的东西。在我的控制器中,我使用setConfig添加数据,但我应该使用Doctrine自动生成的addConfig。