Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php I';我试图从一对夫妻的关系中阅读一本教义集,但我找不到如何阅读。_Php_Symfony_Frameworks_Doctrine - Fatal编程技术网

Php I';我试图从一对夫妻的关系中阅读一本教义集,但我找不到如何阅读。

Php I';我试图从一对夫妻的关系中阅读一本教义集,但我找不到如何阅读。,php,symfony,frameworks,doctrine,Php,Symfony,Frameworks,Doctrine,我用的是Symfony2 这是我的对象播放器: use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** * @ORM\Entity * @ORM\Table(name="player") */ class Player { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\Genera

我用的是Symfony2

这是我的对象播放器:

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="player")
 */
class Player
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    protected $name;

    protected $urlAvatar;

    /**
     * @ORM\Column(type="integer")
     */
    protected $coins;

    /**
     * @ORM\Column(type="integer")
     */
    protected $money;

    /**
     * @ORM\OneToMany(targetEntity="Mercenary", mappedBy="player")
     */
    protected $mercenaries;

    public function __construct()
    {
        $this->mercenaries = new ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set coins
     *
     * @param integer $coins
     */
    public function setCoins($coins)
    {
        $this->coins = $coins;
    }

    /**
     * Get coins
     *
     * @return integer 
     */
    public function getCoins()
    {
        return $this->coins;
    }

    /**
     * Set money
     *
     * @param integer $money
     */
    public function setMoney($money)
    {
        $this->money = $money;
    }

    /**
     * Get money
     *
     * @return integer 
     */
    public function getMoney()
    {
        return $this->money;
    }

    /**
     * Add mercenaries
     *
     * @param IFZ\TowerofDimensionsBundle\Entity\Mercenary $mercenaries
     */
    public function addMercenary(\IFZ\TowerofDimensionsBundle\Entity\Mercenary $mercenaries)
    {
        $this->mercenaries[] = $mercenaries;
    }

    /**
     * Get mercenaries
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getMercenaries()
    {
        return $this->mercenaries;
    }
}
我想阅读雇佣军提供的信息,但我找不到如何阅读。它返回一个条令集合,但我无法继续并从集合中获取所有项目。我不想过滤它们,我只想得到所有的项目。
谢谢你的阅读

您可以迭代
数组集合
,就像您对数组所做的那样:

foreach($player->get雇佣军()作为$雇佣军){
//用$雇佣军做任何你想做的事
}
或在树枝上:

{% for mercenary in player.mercenaries %}
    {# do whatever you want with mercenary #}
{% endfor %}
您还可以从集合中获取数组:

$雇佣军数组=$player->get雇佣军()->toArray();