Symfony 如何实现上下移动功能?
我需要通过单击每个项目附近显示的向上按钮来重新排列显示的项目 我尝试了/**@var DocumentManager$dm*/ $dm=$this->getDocumentManager()Symfony 如何实现上下移动功能?,symfony,Symfony,我需要通过单击每个项目附近显示的向上按钮来重新排列显示的项目 我尝试了/**@var DocumentManager$dm*/ $dm=$this->getDocumentManager() 但它与最后一项交换。我需要向上移动一级。我如何才能做到这一点?它用于向上和向下移动显示的项列表。它用于从数据库获取数据,而不是在客户端移动项。为此,您应该使用javascript。 /** @var MaterializedPathRepository $repository */ $rep
但它与最后一项交换。我需要向上移动一级。我如何才能做到这一点?它用于向上和向下移动显示的项列表。它用于从数据库获取数据,而不是在客户端移动项。为此,您应该使用javascript。
/** @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();