【问题标题】:Symfony Doctrine Nested Set Path To Root QuerySymfony Doctrine 嵌套集路径到根查询
【发布时间】:2010-05-11 09:51:42
【问题描述】:

symfony 有没有办法从一个学说嵌套集合中获取从 id 元素指定的整个路径/路线到 Doctrine_Collection 或数组中的根元素?

【问题讨论】:

    标签: php symfony1 doctrine nested-sets


    【解决方案1】:

    我认为这应该返回你所追求的:

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

    来自docs

    【讨论】:

      【解决方案2】:

      如果您正在考虑构建类似面包屑路径的东西,getPath 会这样做:

      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

      因此,您需要在模型中覆盖 __toString()。如果你不这样做,Doctrine 会尝试通过查找名为“name”、“title”等的列来猜测要写什么。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多