标签: doctrine-collection

DoctrineCollection:toArray()和getData()之间的区别

基本上,如果我有一个DoctrineCollection的DoctrineRecord对象,并想将其转换为数组,我可以使用:

$collection->toArray() 要么 $collection->getData()

但我不明白这两种方法之间的区别.

php doctrine doctrine-collection

3
推荐指数
2
解决办法
3313
查看次数

获取集合中的最后一个元素

我正在尝试获取集合中最后一个元素的属性。我试过了

end($collection)->getProperty()
Run Code Online (Sandbox Code Playgroud)

$collection->last()->getProperty()
Run Code Online (Sandbox Code Playgroud)

没有办法

(告诉我我正尝试getProperty()在布尔值上使用)。

/**
 * Get legs
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getLegs()
{
    return $this->aLegs;
}

public function getLastlegdate()
{
    $legs = $this->aLegs;

    return $legs->last()->getStartDate();
}
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

php collections doctrine symfony doctrine-collection

2
推荐指数
1
解决办法
6122
查看次数