如何实现上下移动功能?

时间:2016-01-29 13:59:42

标签: symfony

我需要通过点击每个项目附近显示的向上按钮重新排列显示的项目 我试过/ ** @var DocumentManager $ dm * /         $ dm = $ this-> getDocumentManager();

    /** @var MaterializedPathRepository $repository */
    $repository = $dm->getRepository(Page::class);

    /* fetch page to swap with */
    /** @var Page $otherPage */
    $otherPage = $repository->findOneBy([
        'site' => $id->getSite()->getId(),
        'sort_index' => $id->getSortIndex()-1
    ]);


    if(null !== $otherPage) {
        $otherPage->setSortIndex($otherPage->getSortIndex()+1);
        $dm->persist($otherPage);
    }

    /* edit the sorting */
    $id->setSortIndex($id->getSortIndex()-1,$position);
    $dm->persist($id);
    $dm->flush();

但它与最后一项交换..我需要向上移动一级......我可以这样做吗?

0 个答案:

没有答案