Php Symfony-2.3实体存储库错误

Php Symfony-2.3实体存储库错误,php,doctrine-orm,repository,entity,symfony-2.3,Php,Doctrine Orm,Repository,Entity,Symfony 2.3,我通常使用2.1或2.2版本的symfony。 今天我在2.3上启动了一个新项目,在创建自定义实体存储库时遇到了一些问题 我的实体是: <?php namespace Acme\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * AnnualProduction * * @ORM\Table(name="Annual_Production") * @ORM\

我通常使用2.1或2.2版本的symfony。 今天我在2.3上启动了一个新项目,在创建自定义实体存储库时遇到了一些问题

我的实体是:

  <?php

    namespace Acme\MyBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**
     * AnnualProduction
     *
     * @ORM\Table(name="Annual_Production")
     * @ORM\Entity(repositoryClass="Acme\MyBundle\Entity\AnnualproductionRepository")
     */
    class AnnualProduction
    {
        /**
         * @var string
         *
         * @ORM\Column(name="device_address", type="string", length=45, nullable=true)
         */
        private $deviceAddress;

        /**
         * @var integer
         *
         * @ORM\Column(name="mese_1", type="integer", nullable=true)
         */
        private $mese1;

        /**
         * @var integer
         *
         * @ORM\Column(name="mese_2", type="integer", nullable=true)
         */

SOME MISSING VAR SET AND GET


         /**
         * @var string
         *
         * @ORM\Column(name="sens_id", type="string", length=45)
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         */
        private $sensId;

        /**
         * @var \DateTime
         *
         * @ORM\Column(name="AAAA", type="date")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         */
        private $aaaa;

    /**
         * Set deviceAddress
         *
         * @param string $deviceAddress
         * @return AnnualProduction
         */
        public function setDeviceAddress($deviceAddress)
        {
            $this->deviceAddress = $deviceAddress;

            return $this;
        }

        /**
         * Get deviceAddress
         *
         * @return string 
         */
        public function getDeviceAddress()
        {
            return $this->deviceAddress;
        }

        /**
         * Set mese1
         *
         * @param integer $mese1
         * @return AnnualProduction
         */
        public function setMese1($mese1)
        {
            $this->mese1 = $mese1;

            return $this;
        }

        /**
         * Get mese1
         *
         * @return integer 
         */
        public function getMese1()
        {
            return $this->mese1;
        }
      /**
         * Set sensId
         *
         * @param string $sensId
         * @return AnnualProduction
         */
        public function setSensId($sensId)
        {
            $this->sensId = $sensId;

            return $this;
        }

        /**
         * Get sensId
         *
         * @return string 
         */
        public function getSensId()
        {
            return $this->sensId;
        }

        /**
         * Set aaaa
         *
         * @param \DateTime $aaaa
         * @return AnnualProduction
         */
        public function setAaaa($aaaa)
        {
            $this->aaaa = $aaaa;

            return $this;
        }

        /**
         * Get aaaa
         *
         * @return \DateTime 
         */
        public function getAaaa()
        {
            return $this->aaaa;
        }
    }

存储库的命名空间错误。您应该使用Acme\MyBundle\Entity\Repository作为名称空间。然后,文件的路径应该是Acme/MyBundle/Entity/Repository/AnnualProduction

您还应该让条令通过以下方式为您生成所有实体:

 php app/console doctrine:generate:entities Acme

然后,您将在Entities文件夹中看到一个名为Repositories的文件夹,所有实体都需要存储在该文件夹中。

问题已解决,事实是/src/acme/myBundle/config/doctor中存储的entity.orm.xml文件比实体文件具有更高的优先级,所以我对实体所做的每一次修改都没有读过


解决方案:完成注释后,删除所有entity.orm.xml文件,并通过终端php命令生成实体。

tx以获取答复。我已将实体注释中的名称空间从:@ORM\entity(repositoryClass=“Acme\MyBundle\entity\AnnualConsumptionRepository”)更改为:@ORM\entity(repositoryClass=“Acme\MyBundle\entity\Repository\AnnualConsumption”),然后使用命令:php-app/console-doctor:generate:entities-Acme,但它只生成实体,未创建存储库文件夹,也未创建存储库文件。我是不是做错了什么?我发现了一个事实,那就是不能自动生成实体/存储库。我在这篇文章中说:我已经在事实中找到了我自己像以前一样生成文件夹和文件的方法。在这种情况下,我的初始配置和您的建议没有区别。我尝试了使用entity/repository forlder和手动生成的文件创建名称空间,但问题仍然存在。
<?php

namespace Acme\MyBundle\Controller;


use Acme\MyBundle\Entity\AnnualProduction;
use Acme\MyBundle\Entity;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints\Date;



class DataController extends Controller{

    public function indexUserAction(){

*
*
*
*
*
   $DailyProduction=$DailyProduction+$em->getRepository('AcmeMyBundle:AnnualProduction')->findByYearMonthDay($year, $month, $day, $productionSensor);
*
*
*
*
   }
}
 php app/console doctrine:generate:entities Acme