Php Can';t从TWIG获取多个元素中的id
我对这个问题越来越着迷了。我在一个实体中有一个ManyToOne列,我需要获取id(即保存在表中的值),但是如果我在twig中获取var,它将使用我链接到实体中显示的名称-预期的名称-但是我如何访问idPhp Can';t从TWIG获取多个元素中的id,php,symfony,doctrine-orm,twig,Php,Symfony,Doctrine Orm,Twig,我对这个问题越来越着迷了。我在一个实体中有一个ManyToOne列,我需要获取id(即保存在表中的值),但是如果我在twig中获取var,它将使用我链接到实体中显示的名称-预期的名称-但是我如何访问id {{profile.CarOneId}} //it gets `BMW 320` {{dump(profile.CarOneId)}} Car {#2458 ▼ +__isInitialized__: true +id: 49 +name: "BMW
{{profile.CarOneId}}
//it gets `BMW 320`
{{dump(profile.CarOneId)}}
Car {#2458 ▼
+__isInitialized__: true
+id: 49
+name: "BMW 320"
+slug: "bmw-320"
+native: true
+perfil: PersistentCollection {#2604 ▶}
…4
}
我需要身份证,所以请用“49”号
Car实体将VAR作为公共:
class Car
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/** @ORM\Column(name="name", type="string", length=100) */
public $name;
/** @ORM\Column(name="slug", type="string", length=100) */
public $slug;
/** @ORM\Column(name="native", type="boolean", nullable=true) */
public $native;
/**
* @ORM\OneToMany(targetEntity="Profile", mappedBy="car")
*/
public $profile;
public function __construct()
{
$this->profile = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
....
有什么想法吗?你能把你的
档案
实体和你展示的getter方法一起包括进来吗?另外,如果profile.CarOneId
返回Car
的对象,您是否尝试了类似profile.CarOneId.id
?/***@var integer**@ORM\manytone(targetEntity=“Car”,inversedBy=“Car”)*@ORM\JoinColumn(name=“Car\u one\u id”,referencedColumnName=“id”)/public$profileCarOneId;/**Get-profileCarOneId**@return integer*/public function getProfileCarOneId(){return$this->profileCarOneId;}注意:我有意在@和文本之间添加空格,以便可以在此处发布。您是否尝试访问我在第一条评论末尾建议的id
属性?@Artamiel:是,是的。我收到一条消息,我试图访问一个空值。