本文介绍了Symfony-Catchable致命错误:传递给Doctrine\Common\Collections\ArrayCollection :: __ construct()的参数1必须为数组类型,给定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试加载页面(Symfony 3.3)时遇到此错误:

I am getting this error while trying to load my page(Symfony 3.3):

看了很多网站,但没有一个能够解决我的问题。

以下是我的实体的示例:

I have looked at many websites but none of them was able to solve my problem.
Below is an example of my entities:

<?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);
   }
}



Company.php



Company.php

<?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;
}
}



Config.php



Config.php

<?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;
}
}


推荐答案

As我以为是造成它的很小的东西。在我的控制器中,我使用setConfig添加数据,但是我应该使用由Doctrine自动生成的addConfig。

As I expected it was something very small that was causing it. In my controller I was using setConfig to add data but instead I should have used the addConfig automatically generated by Doctrine.

这篇关于Symfony-Catchable致命错误:传递给Doctrine\Common\Collections\ArrayCollection :: __ construct()的参数1必须为数组类型,给定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:04