2015-01-02 6 views
0

중첩 트리 분기의 노드를 재정렬하기 위해 컨트롤러 작업을 만들었습니다. DoctrineExtensions documentation에서 예를 들었지만 코드가 실제로 트리를 버리고 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?()중첩 트리의 노드 재정렬 방법 (DoctrineExtensions)

public function orderUpdateAction($id) 
{ 
    $order = $this->request->getPost()['order']; 
    $parent = $this->getLocationById($id); 
    $repository = $this->getRepository(); 
    $previous = null; 

    foreach ($order as $childId) { 
     $child = $this->getLocationById($childId); 

     if (!$child) { 
      throw new \InvalidArgumentException("Unknown location: $childId"); 
     } 

     if ($previous) { 
      $repository->persistAsNextSiblingOf($child, $previous); 
     } else { 
      $repository->persistAsFirstChildOf($child, $parent); 
     } 

     $previous = $child; 
    } 

    $this->entitymanager->flush(); 

    // … 
} 

는 다음을 확인 오류를 반환 :

내 컨트롤러 액션의 코드는 다음과 같습니다

array (size=8) 
    0 => string 'index [1], duplicate on tree root: 1' (length=36) 
    1 => string 'index [2], duplicate on tree root: 1' (length=36) 
    2 => string 'index [3], duplicate on tree root: 1' (length=36) 
    3 => string 'index [4], missing on tree root: 1' (length=34) 
    4 => string 'index [5], missing on tree root: 1' (length=34) 
    5 => string 'index [6], missing on tree root: 1' (length=34) 
    6 => string 'index [7], missing on tree root: 1' (length=34) 
    7 => string 'node [3] has invalid left or right values' (length=41) 

답변

0

당신이해야 루프를 foreach 문을 $this->entitymanager->flush();를 이동합니다.

+0

지금 작동하는지 (이전 프로젝트) 확인할 방법이 없지만 여전히 사용자의 대답이 유효하다고 가정하고 있습니다. 내 질문에 답변 해 주셔서 감사합니다. – olvlvl