Symfony-Catchable致命错误:传递给Doctrine Common Collections ArrayCollection :: __ construct()的参数1必须是类(代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Symfony-Catchable致命错误:传递给Doctrine Common Collections ArrayCollection :: __ construct()的参数1必须是类(代码相关的知识,希望对你有一定的参考价值。
我在尝试加载页面时收到此错误(Symfony 3.3):
可捕获的致命错误:传递给Doctrine Common Collections ArrayCollection :: __ construct()的参数1必须是类型数组,对象给定`。
我看了很多网站,但没有一个能够解决我的问题。 以下是我的实体的示例:
Setting.php
<?php
namespace PressferBundleEntityPressfer;
use DoctrineORMMapping as ORM;
/**
* Setting
*
* @ORMTable(name="pressfer_setting")
* @ORMEntity(repositoryClass="PressferBundleRepositoryPressferSettingRepositor
y")
*/
class Setting
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORMColumn(name="value", type="boolean")
*/
private $value;
/**
* @ORMOneToMany(targetEntity="PressferBundleEntityPressferConfig",
mappedBy="Setting")
*
*/
private $config;
/**
* @ORMManyToOne(targetEntity="PressferBundleEntityCompanyCompany",
inversedBy="settings")
* @ORMJoinColumn(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 DoctrineCommonCollectionsArrayCollection();
}
/**
* Add config
*
* @param PressferBundleEntityPressferConfig $config
*
* @return Setting
*/
public function addConfig(PressferBundleEntityPressferConfig $config)
{
$this->config[] = $config;
return $this;
}
/**
* Remove config
*
* @param PressferBundleEntityPressferConfig $config
*/
public function removeConfig(PressferBundleEntityPressferConfig
$config)
{
$this->config->removeElement($config);
}
}
Company.php
<?php
namespace PressferBundleEntityCompany;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="pf_companies")
*/
class Company
{
/**
* @ORMColumn(type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
/**
* @ORMColumn(type="string", length=255)
*/
private $email;
/**
* @ORMColumn(type="string", nullable=false)
*/
private $subdomain;
/**
* @ORMManyToOne(targetEntity="CompanyInfo")
* @ORMJoinColumn(name="infoId", referencedColumnName="id", onDelete="CASCADE")
*/
private $infoid;
/**
* @ORMOneToMany(targetEntity="PressferBundleEntityPressferSetting", 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 DoctrineCommonCollectionsArrayCollection();
}
/**
* Add setting
*
* @param PressferBundleEntityPressferSetting $setting
*
* @return Company
*/
public function addSetting(PressferBundleEntityPressferSetting $setting)
{
$this->settings[] = $setting;
return $this;
}
/**
* Remove setting
*
* @param PressferBundleEntityPressferSetting $setting
*/
public function removeSetting(PressferBundleEntityPressferSetting $setting)
{
$this->settings->removeElement($setting);
}
/**
* Get settings
*
* @return DoctrineCommonCollectionsCollection
*/
public function getSettings()
{
return $this->settings;
}
}
Config.php
<?php
namespace PressferBundleEntityPressfer;
use DoctrineORMMapping as ORM;
/**
* Config
*
* @ORMTable(name="pressfer_config")
*@ORMEntity(repositoryClass="PressferBundleRepositoryPressferConfigRepository")
*/
class Config
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORMColumn(name="value", type="boolean")
*/
private $value;
/**
* @ORMOneToMany(targetEntity="PressferBundleEntityPressferConfig", mappedBy="dependency")
*/
private $dependency;
/**
* @ORMManyToOne(targetEntity="PressferBundleEntityPressferSetting", 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 DoctrineCommonCollectionsArrayCollection();
}
/**
* Add dependency
*
* @param PressferBundleEntityPressferConfig $dependency
*
* @return Config
*/
public function addDependency(PressferBundleEntityPressferConfig $dependency)
{
$this->dependency[] = $dependency;
return $this;
}
/**
* Remove dependency
*
* @param PressferBundleEntityPressferConfig $dependency
*/
public function removeDependency(PressferBundleEntityPressferConfig $dependency)
{
$this->dependency->removeElement($dependency);
}
/**
* Set setting
*
* @param PressferBundleEntityPressferSetting $setting
*
* @return Config
*/
public function setSetting(PressferBundleEntityPressferSetting $setting = null)
{
$this->Setting = $setting;
return $this;
}
/**
* Get setting
*
* @return PressferBundleEntityPressferSetting
*/
public function getSetting()
{
return $this->Setting;
}
}
答案
正如我所料,这是一个非常小的东西。在我的控制器中,我使用setConfig添加数据,但我应该使用Doctrine自动生成的addConfig。
以上是关于Symfony-Catchable致命错误:传递给Doctrine Common Collections ArrayCollection :: __ construct()的参数1必须是类(代码的主要内容,如果未能解决你的问题,请参考以下文章
致命错误:将 FirebaseData 传递给 tablviewCell 时,索引超出范围