0

エンティティ アカウントに DoctrineExtensions Tree を使用しています。

私は次の結果を得ています:

 $repo = $em->getRepository('NRtworksChartOfAccountsBundle:Accounttree');
 $arrayTree = $repo->childrenHierarchy();

Entity Accounttree は、ドキュメントに続く古典的なエンティティです。

 /**
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="Accounttree")
 * use repository for handy tree functions
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
 */

class Accounttree
{
    /**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */

protected $id;

/**
 * @ORM\Column(type="string", length=100, unique = true)
 */

protected $name;  

 /**
 * @ORM\Column(type="string", length=50)
 */

protected $code;

/**
 * @Gedmo\TreeLeft
 * @ORM\Column(name="lft", type="integer")
 */
protected $lft;

/**
 * @Gedmo\TreeLevel
 * @ORM\Column(name="lvl", type="integer")
 */
protected $lvl;

/**
 * @Gedmo\TreeRight
 * @ORM\Column(name="rgt", type="integer")
 */
protected $rgt;

 /**
 * @Gedmo\TreeRoot
 * @ORM\Column(name="root", type="integer", nullable=true)
 */
protected $root;

/**
 * @Gedmo\TreeParent
 * @ORM\ManyToOne(targetEntity="Accounttree", inversedBy="children")
 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
 */
protected $parent;

/**
 * @ORM\OneToMany(targetEntity="Accounttree", mappedBy="parent")
 * @ORM\OrderBy({"lft" = "ASC"})
 */
protected $children;


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

    /**
     * Set name
     *
     * @param string $name
     * @return Account
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set code
     *
     * @param string $code
     * @return Account
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

    /**
     * Get code
     *
     * @return string 
     */
    public function getCode()
    {
        return $this->code;
    }

    public function setParent(Accounttree $parent=null)
    {
        $this->parent = $parent;
    }

    public function getParent()
    {
        return $this->parent;
    }
}

私の小枝で

{{ account.getParent().getId() }}

私に与えます:

ContextErrorException: Notice: Array to string conversion in /home/eagle1/www/Symfony24/app/cache/dev/classes.php line 4604


    in /home/eagle1/www/Symfony24/app/cache/dev/classes.php line 4604
   at ErrorHandler->handle('8', 'Array to string conversion', '/home/eagle1/www/Symfony24/app/cache/dev/classes.php', '4604', array('object' => array('id' => '2', 'name' => 'Revenue', 'code' => '700000', 'lft' => '2', 'lvl' => '1', 'rgt' => '11', 'root' => '1', '__children' => array(array('id' => '4', 'name' => 'Sales', 'code' => '701000', 'lft' => '3', 'lvl' => '2', 'rgt' => '6', 'root' => '1', '__children' => array(array('id' => '7', 'name' => 'Products', 'code' => '701100', 'lft' => '4', 'lvl' => '3', 'rgt' => '5', 'root' => '1', '__children' => array()))), array('id' => '5', 'name' => 'Discount', 'code' => '702000', 'lft' => '7', 'lvl' => '2', 'rgt' => '8', 'root' => '1', '__children' => array()), array('id' => '6', 'name' => 'Subsidies', 'code' => '703000', 'lft' => '9', 'lvl' => '2', 'rgt' => '10', 'root' => '1', '__children' => array()))), 'item' => 'getParent', 'arguments' => array(), 'type' => 'method', 'isDefinedTest' => false, 'ignoreStrictCheck' => false))
   at sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', 'getParent', 'array', array('id' => '2', 'name' => 'Revenue', 'code' => '700000', 'lft' => '2', 'lvl' => '1', 'rgt' => '11', 'root' => '1', '__children' => array(array('id' => '4', 'name' => 'Sales', 'code' => '701000', 'lft' => '3', 'lvl' => '2', 'rgt' => '6', 'root' => '1', '__children' => array(array('id' => '7', 'name' => 'Products', 'code' => '701100', 'lft' => '4', 'lvl' => '3', 'rgt' => '5', 'root' => '1', '__children' => array()))), array('id' => '5', 'name' => 'Discount', 'code' => '702000', 'lft' => '7', 'lvl' => '2', 'rgt' => '8', 'root' => '1', '__children' => array()), array('id' => '6', 'name' => 'Subsidies', 'code' => '703000', 'lft' => '9', 'lvl' => '2', 'rgt' => '10', 'root' => '1', '__children' => array())))) in /home/eagle1/www/Symfony24/app/cache/dev/classes.php line 4604

および {{Account.parent.id}}

与える

 Key "parent" for array with keys "id, name, code, lft, lvl, rgt, root, __children" does not exist in NRtworksChartOfAccountsBundle:ChartOfAccounts:COA2.html.twig at line 10 

私が間違っていることを見つけることができません。

ヘルプ ?

4

1 に答える 1