Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条令字段在数据库中有值,但映射时为空_Php_Mysql_Symfony_Doctrine Orm_Doctrine - Fatal编程技术网

Php 条令字段在数据库中有值,但映射时为空

Php 条令字段在数据库中有值,但映射时为空,php,mysql,symfony,doctrine-orm,doctrine,Php,Mysql,Symfony,Doctrine Orm,Doctrine,我对原则有一个奇怪的问题 当我使用find(id)查找实体时,除了id之外,所有字段都是空的。我已经仔细检查了数据库中的值,它们都不是空的 奇怪的是,当我发出一个本机mysql查询并试图找到doctrine试图获取的实体时,我得到了非空值,所以这可能是一个doctrine获取值的问题 这是我的实体: use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** * * * @O

我对
原则有一个奇怪的问题

当我使用
find(id)
查找实体时,除了id之外,所有字段都是空的。我已经仔细检查了数据库中的值,它们都不是空的

奇怪的是,当我发出一个本机mysql查询并试图找到doctrine试图获取的实体时,我得到了非空值,所以这可能是一个doctrine获取值的问题

这是我的实体:

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * 
 *
 * @ORM\Entity()
 * @ORM\Table(name="hui_address")
 */
class Address
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    protected $client_id;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    protected $region_id;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $street;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $city;

    /**
     * @ORM\Column(name="`state`", type="text", nullable=true)
     */
    protected $state;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $zip_code;

    /**
     * @ORM\Column(type="float", precision=10, scale=6, nullable=true)
     */
    protected $latitude;

    /**
     * @ORM\Column(type="float", precision=10, scale=6, nullable=true)
     */
    protected $longitude;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $notes;

    /**
     * @ORM\Column(name="`status`", type="boolean", nullable=true)
     */
    protected $status;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     */
    protected $archive;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $created_at;

    /**
     * @ORM\OneToMany(targetEntity="Store", mappedBy="address")
     * @ORM\JoinColumn(name="id", referencedColumnName="address_id")
     */
    protected $Stores;

    /**
     * @ORM\ManyToOne(targetEntity="Client", inversedBy="Addresses")
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
     */
    protected $client;

    /**
     * @ORM\OneToMany(targetEntity="Client", mappedBy="PPBAddress")
     * @ORM\JoinColumn(name="id", referencedColumnName="ppb_address_id")
     */
    protected $clientHQ;

    /**
     * @ORM\ManyToOne(targetEntity="Region", inversedBy="Addresses")
     * @ORM\JoinColumn(name="region_id", referencedColumnName="id")
     */
    protected $region;

    public function __construct()
    {
        if (!$this->created_at) {
            $this->created_at = new \DateTime();
        }

        $this->Clients = new ArrayCollection();
        $this->Stores = new ArrayCollection();
    }

    public function __toString()
    {
        return (!$this->street || strlen($this->street) == 0 || !$this->city || !$this->city)
            ? "Address incomplete"
            : sprintf('%s, %s %s %s', $this->street, $this->city, $this->state, $this->zip_code);
    }

     public function __sleep()
    {
         return array('id', 'client_id', 'region_id', 'street', 'city', 'state', 'zip_code', 'latitude', 'longitude', 'notes', 'status', 'archive', 'created_at');
    }
}

实体类中缺少getter和setter

php bin/console doctrine:generate:entities *your bundle*

将自动生成它们

原则
没有问题。事实证明,
地址
是从本机查询中获取的,并且只选择了
id
,这就是为什么我得到的是
id
的值,其余的为null

这是如何找到地址的:

$query = $this->getManager()->createNativeQuery('SELECT .... ')

你能粘贴控制器和查看代码吗?您访问的行的一个示例感谢JGrinon的评论,我发现了问题我马上会发布答案谢谢您的回答,为了清楚起见,我省略了,它们在我的代码中