Database Symfony 2条令请求对象Id为空白页

Database Symfony 2条令请求对象Id为空白页,database,symfony,doctrine,fetch,Database,Symfony,Doctrine,Fetch,在主控制器中执行简单查询时,例如: public function newAdCreatedAction($id) { $em = $this->getDoctrine()->getManager()->getRepository('websiteAdsBundle:AdsList'); $article = $em->findById($id); return $this->render('websiteAdsBundle:Default

在主控制器中执行简单查询时,例如:

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));
}
我在日志文件中有一个空白页,我收到以下消息错误(如果有帮助):

我认为这与@ORM\Join语句有关,但我不知道它是什么。 我猜双向关联,细枝的转储是不工作的

网站/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());
}
}
中间人回答:
目前我正在使用

\Doctrine\Common\Util\Debug::dump($article);
以获得无问题的输出。显然,有一些扩展允许以更恰当的方式回显输出


如果我找到更好的东西,我会回来把它贴在这里。

如果你在这里使用了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;
}

您可能在
模板中使用了
{{dump()}
,是的,我使用了。为什么不呢?是否完成转储以查看对象内部的内容?此外,当php控制器中的var_dump($ads)时,页面将永远无法加载。。。就好像它在呼唤整个symfony2/教义。。我不明白。如果执行
dump()
,它将从当前上下文中转储所有变量(在您的情况下约为119 MB)。你能展示一下你执行
dump
的模板片段吗?我不明白它为什么会有这种行为。显然,我只需要调用一个特定的对象(带有照片的adslist)。我正在添加模板,但很简单,它是一堆div,我启动了{{dump(article)}}或一个“ad”,我在这个例子中放了一篇文章,但它应该是“ad”。没有
var\u dump-driven development
这样的东西。这是一种玩笑;)<代码>var_dump
在您不必调试大型结构,只调试简单对象时非常有用。
<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>
\Doctrine\Common\Util\Debug::dump($article);
public function registerBundles()
{
    //...

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        // ...
    }

    return $bundles;
}