0

例のように、カテゴリ構造 (Doctrine2 の Gedmo Nested Tree 拡張機能を使用) があります: https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#tree-entity-example

問題は、次のようにすべてのツリーをテーブルとして表示する方法です。

<table>
   <tr>
      <td>Category-1 name</td>
      <td>Category-1 other data</td>
   </tr>
   <tr>
      <td>Category-2 name</td>
      <td>Category-2 other data</td>
   </tr>
   <tr>
      <td><span class="indent">---</span>Subcategory-2-1 name</td>
      <td>Subcategory-2-1 other data</td>
   </tr>
   <tr>
      <td><span class="indent">---</span><span class="indent">---</span>Subcategory-2-1-1 name</td>
      <td>Subcategory-2-1-1 other data</td>
   </tr>
   <tr>
      <td>Category-3 name</td>
      <td>Category-3 other data</td>
   </tr>
</table>

別の言い方をすれば、1 つのクエリでレベル パラメータを含む単純なリストとしてツリーを取得する必要があります。リストを配列 (getNodesHierarchy) としてのみ取得する方法を見つけましたが、findAll() を呼び出した場合のようにコレクションとして取得する必要があります。

4

1 に答える 1

0

解決策を見つけました:

class CategoryRepository extends NestedTreeRepository
{
    public function getTreeList()
    {
        return $this->getNodesHierarchyQuery()->getResult();
    }
}
于 2014-06-18T13:47:35.103 に答える