Mongodb Symfony2可重复使用的可排序列表
我已将Symfony1食谱的这一条目改写为Symfony2。我的第一个目标是经典的可排序列表: 所有文档(MongoDB)都有一个位置字段,该字段是整数类型,显示顺序为整数 我创建了一个服务类可排序表,其中包含以下方法:Mongodb Symfony2可重复使用的可排序列表,mongodb,symfony,Mongodb,Symfony,我已将Symfony1食谱的这一条目改写为Symfony2。我的第一个目标是经典的可排序列表: 所有文档(MongoDB)都有一个位置字段,该字段是整数类型,显示顺序为整数 我创建了一个服务类可排序表,其中包含以下方法: class Sortable { //Return the position of the document public function getByPosition($position = 1, $document, $site, $item = null
class Sortable
{
//Return the position of the document
public function getByPosition($position = 1, $document, $site, $item = null){ /**/ }
//Return all elements sorted by position
public function getAllByPosition($document, $site){/**/}
//Return the max position of the items within a parent item
public function getMaxPosition($document, $site, $parent = null){/**/}
//Swap the position between $itemOne and $itemTwo
public function swapWith($itemOne, $itemTwo, $document){/**/}
//Set the new position => +1
public function executeUp($document, $id){/**/}
//Set the new position => -1
public function executeDown($document, $id){/**/}
//Persist document with the new position
public function save($item, $document){/**/}
}
这很好,但主要问题是这个类很难重用
-$document var是数据库中要使用的文档的名称,例如在createQueryBuilder('MyBundle'.$document)
-$site var是我的应用程序的站点,因为每个用户都有一个站点
-$parent var的类型为$document,它是相同类型文档的父级
我的问题是,这很难重用,我必须在控制器操作中调用上面的所有方法,然后检查细枝模板中的位置。我想实现一个twig扩展,它调用我的服务并执行我在控制器和twig中执行的所有逻辑。而且它可以与任何文档一起使用
我怎么能得到这个