在主控制器中执行简单查询时,例如:
public function newAdCreatedAction($id)
{
$em = $this->getDoctrine()->getManager()->getRepository('websiteAdsBundle:AdsList');
$article = $em->findById($id);
return $this->render('websiteAdsBundle:Default:newAdCreated.html.twig',array('article'=>$article));
}
我在日志文件中有一个空白页面我收到以下消息错误(如果有帮助):
//Bunch of kernelerrors... here and then:
[2014-06-09 14:07:53] doctrine.DEBUG: SET NAMES UTF8 [] []
[2014-06-09 14:07:53] doctrine.DEBUG: SELECT t0.id AS id1, t0.username AS username2,t0.email AS email3, t0.telephone AS telephone4, t0.display_phone AS display_phone5, t0.title AS title6, t0.description AS description7, t0.country AS country8, t0.region AS region9, t0.department AS department10, t0.address AS address11, t0.city AS city12, t0.zip_code AS zip_code13, t0.status_pro AS status_pro14, t0.creationtime AS creationtime15, t0.updatetime AS updatetime16, t0.publication AS publication17 FROM AdsList t0 WHERE t0.id = ? ["53"] []
[2014-06-09 14:07:55] emergency.EMERGENCY: Allowed memory size of 134217728 bytes exhausted (tried to allocate 125573121 bytes) {"type":1,"file":"/home/alfonso/sites/ads.website.com/public_html/vendor/twig/twig/lib/Twig/Extension/Debug.php","line":66} []
我认为这与@ORM \ Join语句有关,但我无法弄清楚它是什么。 我想有双向关联,Twig的转储无法正常工作
网站/ AdsBundle / Entity / AdsList.php类:
<?php
namespace website\AdsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use website\AdsBundle\Entity\Photos;
/**
* AdsList
*
* @ORM\Table()
* @ORM\Entity
* @ORM\Entity(repositoryClass="website\AdsBundle\Entity\AdsListRepository")
* @ORM\HasLifecycleCallbacks()
*/
class AdsList
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="telephone", type="string", length=255)
*/
private $telephone;
/**
* @var string
*
* @ORM\Column(name="display_phone", type="string", length=255)
*/
private $displayPhone;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="description", type="text")
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="country", type="string", length=255)
*/
private $country;
/**
* @var string
*
* @ORM\Column(name="region", type="string", length=255)
*/
private $region;
/**
* @var string
*
* @ORM\Column(name="department", type="string", length=255)
*/
private $department;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255)
*/
private $city;
/**
* @var string
*
* @ORM\Column(name="zip_code", type="string", length=255)
*/
private $zipCode;
/**
* @var string
*
* @ORM\Column(name="status_pro", type="string", length=255)
*/
private $statusPro;
/**
* @var \DateTime
*
* @ORM\Column(name="creationtime", type="datetime")
*/
private $creationtime;
/**
* @var \DateTime
*
* @ORM\Column(name="updatetime", type="datetime")
*/
private $updatetime;
/**
* @var boolean
*
* @ORM\Column(name="publication", type="boolean")
*/
private $publication;
/**
* @ORM\OneToMany(targetEntity="website\AdsBundle\Entity\Photos",mappedBy="adslist", cascade={"persist"})
*/
protected $photos;
/**
* Set photos
*
* @param \website\AdsBundle\Entity\Photos $photos
* @return AdsList
*/
public function setPhotos(\website\AdsBundle\Entity\Photos $photos = null)
{
$this->photos = $photos;
return $this;
}
/**
* Get photos
*
* @return \website\AdsBundle\Entity\Photos
*/
public function getPhotos()
{
return $this->photos;
}
/**
* Add photos
*
* @param \website\AdsBundle\Entity\Photos $photos
* @return AdsList
*/
public function addPhoto(\website\AdsBundle\Entity\Photos $photos)
{
$this->photos[] = $photos;
$photos->setAdslist($this);
return $this;
}
/**
* Remove photos
*
* @param \website\AdsBundle\Entity\Photos $photos
*/
public function removePhoto(\website\AdsBundle\Entity\Photos $photos)
{
$this->photos->removeElement($photos);
}
public function __construct() {
$this->creationtime=new \Datetime;
$this->photos = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return AdsList
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set email
*
* @param string $email
* @return AdsList
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set telephone
*
* @param string $telephone
* @return AdsList
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set displayPhone
*
* @param string $displayPhone
* @return AdsList
*/
public function setDisplayPhone($displayPhone)
{
$this->displayPhone = $displayPhone;
return $this;
}
/**
* Get displayPhone
*
* @return string
*/
public function getDisplayPhone()
{
return $this->displayPhone;
}
/**
* Set title
*
* @param string $title
* @return AdsList
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return AdsList
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set country
*
* @param string $country
* @return AdsList
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set region
*
* @param string $region
* @return AdsList
*/
public function setRegion($region)
{
$this->region = $region;
return $this;
}
/**
* Get region
*
* @return string
*/
public function getRegion()
{
return $this->region;
}
/**
* Set department
*
* @param string $department
* @return AdsList
*/
public function setDepartment($department)
{
$this->department = $department;
return $this;
}
/**
* Get department
*
* @return string
*/
public function getDepartment()
{
return $this->department;
}
/**
* Set address
*
* @param string $address
* @return AdsList
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set city
*
* @param string $city
* @return AdsList
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set zipCode
*
* @param string $zipCode
* @return AdsList
*/
public function setZipCode($zipCode)
{
$this->zipCode = $zipCode;
return $this;
}
/**
* Get zipCode
*
* @return string
*/
public function getZipCode()
{
return $this->zipCode;
}
/**
* Set statusPro
*
* @param string $statusPro
* @return AdsList
*/
public function setStatusPro($statusPro)
{
$this->statusPro = $statusPro;
return $this;
}
/**
* Get statusPro
*
* @return string
*/
public function getStatusPro()
{
return $this->statusPro;
}
/**
* Set creationtime
*
* @param \DateTime $creationtime
* @return test
*/
public function setCreationtime($creationtime)
{
$this->creationtime = $creationtime;
return $this;
}
/**
* Get creationtime
*
* @return \DateTime
*/
public function getCreationtime()
{
return $this->creationtime;
}
/**
* Set updatetime
*
* @param \DateTime $updatetime
* @return Test
*/
public function setUpdatetime($updatetime)
{
$this->updatetime = $updatetime;
return $this;
}
/**
* Get updatetime
*
* @return \DateTime
*/
public function getUpdatetime()
{
return $this->updatetime;
}
/**
* Set publication
*
* @param boolean $publication
* @return test
*/
public function setPublication($publication)
{
$this->publication = $publication;
return $this;
}
/**
* Get publication
*
* @return boolean
*/
public function getPublication()
{
return $this->publication;
}
// Callback
/**
* @ORM\PreUpdate
*/
public function udpateDate()
{
$this->setUpdatetime(new \DateTime());
}
}
照片类如下:
<?php
namespace website\AdsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Photos
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="website\AdsBundle\Entity\PhotosRepository")
* @ORM\HasLifecycleCallbacks
*/
class Photos
{
/**
* @ORM\ManyToOne(targetEntity="website\AdsBundle\Entity\AdsList", inversedBy="photos")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="adslist_id", referencedColumnName="id")
* })
*/
protected $adslist;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="photo_path", type="string", length=255)
*/
private $photoPath;
/**
* @var string
*
* @ORM\Column(name="thumbnail_path", type="string", length=255)
*/
private $thumbnailPath;
/**
* @Assert\File(maxSize="6000000")
*/
private $file;
private $tempFilename;
public function setFile(UploadedFile $file)
{
$this->file = $file;
if (null !== $this->photoPath) {
$this->tempFilename = $this->photoPath;
// reset values
}
}
public function getFile()
{
return $this->file;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set photoPath
*
* @param string $photoPath
* @return Photos
*/
public function setPhotoPath($photoPath)
{
$this->photoPath = $photoPath;
return $this;
}
/**
* Get photoPath
*
* @return string
*/
public function getPhotoPath()
{
return $this->photoPath;
}
/**
* Set thumbnailPath
*
* @param string $thumbnailPath
* @return Photos
*/
public function setThumbnailPath($thumbnailPath)
{
$this->thumbnailPath = $thumbnailPath;
return $this;
}
/**
* Get thumbnailPath
*
* @return string
*/
public function getThumbnailPath()
{
return $this->thumbnailPath;
}
/**
*
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if($this->file === null){
return;
}
//$this->extension = $this->file->guessExtention(); // In my case I don't need it
$this->photoPath = $this->file->getClientOriginalName();
}
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
if($this->file === null){
return;
}
if(null !== $this->tempFilename)
{
$oldFile = $this->getUploadRootDir().'/'.$this->tempFilename;
if(file_exists($oldFile)){
unlink($oldFile);
}
}
$this->file->move(
$this->getUploadRootDir(),
$this->id.'.'.$this->photoPath
);
}
/**
* @ORM\PreRemove()
*/
public function PreRemoveUpload()
{
$this->tempFilename = $this->getUploadRootDir().'/'.$this->id.''.$this->photoPath;
}
/**
* @ORM\PostRemove()
*/
public function removeUpload()
{
if(filex_exists($this->tempFilename))
{
unlink($this->tempFilename);
}
}
public function getUploadDir()
{
return '/upload/img';
}
public function getUploadRootDir()
{
return __DIR__.'/../../../../web'.$this->getUploadDir();
}
public function getWebPath()
{
return $this->getUploadDir().'/'.$this->getId().'.'.$this->getPhotoPath();
}
public function getMyWebPath()
{
return $this->getUploadDir().'/'.$this->getPhotoPath();
}
/**
* Set adslist
*
* @param \website\AdsBundle\Entity\AdsList $adslist
* @return Photos
*/
public function setAdslist(\website\AdsBundle\Entity\AdsList $adslist = null)
{
$this->adslist = $adslist;
return $this;
}
/**
* Get adslist
*
* @return \website\AdsBundle\Entity\AdsList
*/
public function getAdslist()
{
return $this->adslist;
}
}
编辑:
我添加了bartek提出的一块树枝模板:
<body class="metro">
<div class="page secondary">
<div class="page-header">
<div class="div_header">
<img class="logo" src="{{ website_path_swap }}/files/images/logo.png" />
</div>
<div class="div_header">
<h2 class=""></h2>
</div>
</div>
<div class="page-region">
<div class="row">
<div class="span6">
<div>
{{ dump(article) }}
</div>
</div>
</div>
</div>
</div>
</body>
答案 0 :(得分:0)
中介回答: 现在我正在使用
\Doctrine\Common\Util\Debug::dump($article);
为了获得没有问题的输出。显然有一些扩展允许以更恰当的方式回显输出。
如果我找到更好的东西,我会回来发布。
答案 1 :(得分:0)
如果您最终使用Symfony 2.6+,请确保在AppKernel.php中注册DebugBundle
public function registerBundles()
{
//...
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
// ...
}
return $bundles;
}