2013-07-29 2 views
1

내 응용 프로그램에서 pdf 보고서를 생성하기 위해 wkhtmltopdf를 사용하고 있지만 pdf가 생성되면 pdf에 로그인 페이지가 있습니다.Wkhtmltopdf symfony2의 로그인 페이지로 리디렉션

이 내 지침 :

public function exportPdfAction($id = 0) 
{ 
    $em = $this->container->get('doctrine')->getEntityManager(); 
    $id = $this->get('request')->get($this->admin->getIdParameter()); 
    $object = $this->admin->getObject($id); 


    if (!$object) { 
     throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id)); 
    } 

    if (false === $this->admin->isGranted('VIEW', $object)) { 
     throw new AccessDeniedException(); 
    } 

    $pageUrl = $this->generateUrl('admin_rh_leave_conge_show', array('id'=>$id), true); // use absolute path! 

    return new Response(
     $this->get('knp_snappy.pdf')->getOutput($pageUrl), 
     200, 
     array(
      'Content-Type'   => 'application/pdf', 
      'Content-Disposition' => 'attachment; filename="Fiche_conge.pdf"' 

     ) 
    ); 
} 

내가 어떻게이 문제를 해결할 수 있습니까?

+0

유용한 답을 원한다면 좀 더 자세하게 입력해야 할 것입니다. – cheesemacfly

+0

그래서 내 질문을 업데이트 할 것입니다 – soufiane

+0

내 질문이 업데이트되었습니다 – soufiane

답변

0

나는 그 번들과 비슷한 문제가있었습니다. 필자의 경우 명령 줄에서 스크립트가 실행되고 있다는 문제가있었습니다. 그리고 문제는 실행 된 사용자가 소나타 관리에서 인증되지 않았다는 것입니다.

따라서 pdf를 호출하는 것이 사용자에 로그인되어 있고 세션을 잃어 버리게 될 프로덕션 및 개발 환경 사이를 전환하지 말고 다시 로그인해야합니다.

따라서 pdf 생성을 호출하는 스크립트가 올바르게 인증되고 sonata_admin_role (sonata admin 백엔드에 대한 액세스 권한)이 있는지 확인하십시오.

희망이 있습니다.

5

조금 늦었지만 정확히 동일한 문제가있어 해결책을 찾았습니다. getOutput() -method에서 두 번째 매개 변수로 옵션을 전달할 수 있습니다. 이러한 옵션 중 하나는 cookie입니다 :

use Symfony\Component\HttpFoundation\Response; 
... 

$session = $this->get('session'); 
$session->save(); 
session_write_close(); 

return new Response(
    $this->get('knp_snappy.pdf')->getOutput(
     $pageUrl, 
     array('cookie' => array($session->getName() => $session->getId())) 
    ), 
    200, 
    array(
     'Content-Type' => 'application/pdf', 
    ) 
); 

은 자세한 내용은 https://code.google.com/p/wkhtmltopdf/issues/detail?id=356https://github.com/KnpLabs/KnpSnappyBundle/issues/42를 참조하십시오.

관련 문제