似乎我的Symfony2项目的prod环境中的学说不能正常工作。
当我尝试执行以下代码时:
$query = $em->createQuery("SELECT c FROM MyProjectDataTierBundle:WidgetContainer c WHERE c.identity = ?1");
$query->setParameter(1, $container);
$results = $query->getResult();
$container = $results[0];
$widgets = $container->getWidgets();
在开发环境中它正常运行并返回一个小部件的ArrayCollection,但是当我在prod环境中尝试这个时,我得到一个空数组。
我尝试删除缓存,但这无济于事。
下面我复制了带有映射的类,我做错了吗?
WidgetContainer.php
<?php
namespace MyProject\DataTierBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity()
*
*/
class WidgetContainer {
/**
* @var integer
* @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 string
* @ORM\Column(name="identity", type="string", length=255)
*/
private $identity;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="Widget",mappedBy="widgetContainer")
*/
private $widgets;
public function getId() { return $this->id; }
public function setId($id) { $this->id = $id; return $this; }
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; return $this; }
public function getIdentity() { return $this->identity; }
public function setIdentity($identity) { $this->identity = $identity; return $this; }
public function getWidgets() { return $this->widgets; }
public function setWidgets($widgets) { $this->widgets = $widgets; return $this; }
public function __construct() {
$this->widgets = new ArrayCollection();
}
}
?>
Widget.php
<?php
namespace MyProject\DataTierBundle\Entity;
use MyProject\DataTierBundle\Entity\Traits\TTimeStampable;
use MyProject\DataTierBundle\Entity\Traits\TOrderableInt;
use Doctrine\ORM\Mapping as ORM;
/**
* Widget
*
* @ORM\Table()
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"content" = "ContentWidget", "slider" = "SliderWidget"})
*/
class Widget {
/**
* @var integer
* @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;
/**
* Can be small, medium, large, extra large
* @ORM\Column(name="size", type="string", length=20)
*/
private $size = "small";
/**
* @var boolean
* @ORM\Column(name="active", type="boolean")
*/
private $active = false;
/**
* @var string
* @ORM\Column(type="string", length=5)
*/
private $lang;
/**
* @ORM\ManyToOne(targetEntity="WidgetContainer", inversedBy="widgets")
*/
private $widgetContainer;
public function getId() { return $this->id; }
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; return $this; }
public function getActive() { return $this->active; }
public function setActive($active) { $this->active = $active; return $this; }
public function getLang() { return $this->lang; }
public function setLang($lang) { $this->lang = $lang; return $this; }
public function getSize() { return $this->size; }
public function setSize($size) { $this->size = $size; return $this; }
public function getWidgetContainer() { return $this->widgetContainer; }
public function setWidgetContainer($widgetContainer) { $this->widgetContainer = $widgetContainer; return $this; }
use TTimeStampable;
use TOrderableInt;
}
?>
SliderWidget.php
<?php
namespace MyProject\DataTierBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class SliderWidget extends Widget {
/**
* @ORM\OneToMany(targetEntity="SliderWidgetSlide", mappedBy="sliderWidget")
*/
private $slides;
public function getSlides() {
return $this->slides;
}
public function setSlides($slides) {
$this->slides = $slides;
return $this;
}
}