我有一个简单的symfony 2设置与Doctrine ORM和一些下划线分隔字段名称(例如“error_page”)的数据库。查询该从来没有给一个结果(的getTitle确实给结果,getErrorPage总是空)和symfony的给我一个错误:Symfony 2 Doctrine ODM返回现有字段上的错误
Method "error_page" for object "My\CmsBundle\Document\Website" does not exist in MyCmsBundle:Default:dashboard.html.twig at line 5
我想不通为什么......我的文件看起来是这样的:
<?php
// src/My/CmsBundle/Document/Website.php
namespace My\CmsBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document(
* collection="websites"
*)
*/
class Website
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
*/
protected $slug;
/**
* @MongoDB\Field(type="string", name="error_page")
*/
protected $error_page = "";
/**
* @MongoDB\String
*/
protected $title;
/**
* @MongoDB\String(name="seo_title")
*/
protected $seo_title;
/**
* @MongoDB\String
*/
protected $seo_description;
/**
* @MongoDB\Collection
*/
protected $url = array();
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set slug
*
* @param string $slug
* @return self
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string $slug
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set title
*
* @param string $title
* @return self
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set errorPage
*
* @param string $errorPage
* @return self
*/
public function setErrorPage($errorPage)
{
$this->error_page = $errorPage;
return $this;
}
/**
* Get errorPage
*
* @return string $errorPage
*/
public function getErrorPage()
{
return $this->error_page;
}
/**
* Set url
*
* @param collection $url
* @return self
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return collection $url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set seoTitle
*
* @param string $seoTitle
* @return self
*/
public function setSeoTitle($seoTitle)
{
$this->seo_title = $seoTitle;
return $this;
}
/**
* Get seoTitle
*
* @return string $seoTitle
*/
public function getSeoTitle()
{
return $this->seo_title;
}
/**
* Set seoDescription
*
* @param string $seoDescription
* @return self
*/
public function setSeoDescription($seoDescription)
{
$this->seo_description = $seoDescription;
return $this;
}
/**
* Get seoDescription
*
* @return string $seoDescription
*/
public function getSeoDescription()
{
return $this->seo_description;
}
}
通过本文档创建文档的方式很好。如预期的那样,字段名称也设置为error_page ...我在这里处于亏损状态:S
在Twig中使用camelCase:'{{document.errorPage}}' – malcolm