official website 中的这个片段按预期工作:
$treeObject = Doctrine::getTable('Category')->getTree();
$rootColumnName = $treeObject->getAttribute('rootColumnName');
foreach ($treeObject->fetchRoots() as $root) {
$options = array(
'root_id' => $root->$rootColumnName
);
foreach($treeObject->fetchTree($options) as $node) {
echo str_repeat(' ', $node['level']) . $node['name'] . "\n";
}
}
但我看到有几十个查询发送到数据库。我怎么能一口做到?
最佳答案
试试这个:
Doctrine_Core::getTable('YourTableWithTree')->createQuery('tree')
->addOrderBy('tree.root_id ASC')
->addOrderBy('tree.lft ASC');
关于php - 如何使用 Doctrine 在单个查询中获取整个树?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2339800/