开发者

Symfony Doctrine Nested Set Path To Root Query

开发者 https://www.devze.com 2022-12-29 17:34 出处:网络
Is there a way in symfony to get from a doctrine nested set the whole path/route from a s开发者_C百科pecified by id element to the root element in a Doctrine_Collection or array ?I think this should r

Is there a way in symfony to get from a doctrine nested set the whole path/route from a s开发者_C百科pecified by id element to the root element in a Doctrine_Collection or array ?


I think this should return what you are after:

$obj->getNode()->getAncestors();

From the docs


If you're thinking of building something like a breadcrumb trail, getPath would do it:

getPath
public string getPath(string seperator, mixed includeRecord, bool includeNode)

gets path to node from root, uses record::toString() method to get node names

Parameters:
    seperator - path seperator
    includeNode - whether or not to include node at end of path
Returns:
    string representation of path

http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_node_nestedset.html#getPath%28%29

So you need to override __toString() in your model. If you don't, Doctrine will try to guess what to write by looking for columns called "name", "title" and the like.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号