2017-03-13 2 views
1

symfony 2.8 (php5.4 포함)에서 응용 프로그램을 만들고 내 양식 (joom)에서 json 형식의 API를 통해 프로젝트 목록을 표시하려고합니다. 이제 막 붙어서 어떻게해야할지 모르겠다. 당신은 같은 두 번째 인수로 검색을 통과 할 수symfony 양식의 API Json

/** 
* @Route("/form") 
*/ 
public function formAction(Request $request) 
{ 

    $url = 'https://website.com/projects.json'; 
    $get_json = file_get_contents($url); 
    $json = json_decode($get_json); 

    $form = $this->createFormBuilder() 
    ->add('Project', 'choice') // <-- ??? 
    ->add('send', 'submit' ,array('label' => 'Envoyer')) 
    ->getForm(); 
    $form->handleRequest($request); 

    return $this->render('StatBundle:Default:form.html.twig', array('form' => $form->createView(), 'project' => $json)); 

} 

답변

0

: 는 내가 거기에 테이블 "프로젝트"내가 여기에 프로젝트 의 이름을 표시하는 컬럼의 이름을 '대상 원하는 API의 데이터베이스를 아는 것은 내 코드입니다 배열 예 :

$jsonAsArray = json_decode($get_json, true); // with true return an array 

$builder->add('Project', 'choice', array(
    'choices' => $jsonAsArray, 
    // *this line is important, depends of the data* 
    'choices_as_values' => false, 
)); 

자세한 정보 in the doc here. 내가 값을 설정하면

희망이 도움

+0

덕분에이 ** 'choises_as_values'나를위한 작품이다 => 거짓 ** – countrystores

+0

안녕하세요 @countrystores 당신은 환영합니다! 귀하의 의견으로 답변을 업데이트하십시오. – Matteo

+0

안녕하십니까? 답장이 문제가 해결 되었으면 [확인] (http://meta.stackexchange.com/q/5234/179419)를 클릭하여 확인하십시오. 이는 해결책을 찾았으며 응답자와 자신에게 어느 정도의 평판을 제공한다는 것을 더 넓은 커뮤니티에 나타냅니다. 이를 수행 할 의무는 없습니다. – Matteo