2016-09-13 2 views
0

폼 객체 내의 속성에 액세스해야합니다. 문제는 액세스하려는 속성이 형식으로 렌더링되지 않고 contractType 클래스에서 선언되지 않는다는 것입니다.Symfony 2.7 : 폼 객체 내에서 렌더링 된 속성이 액세스되지 않습니다.

class ContractType extends AbstractType 
    { 
     /** 
     * @param FormBuilderInterface $builder 
     * @param array $options 
     */ 
     public function buildForm(FormBuilderInterface $builder, array $options) 
     { 
      $builder 
       ->add('rcode1', new TextType(), array('label' => 'rcode 1')) 
       ->add('rcode2', new TextType(), array('label' => 'rcode 2')); 
     } 
... 
} 

덤프 형태 개체 :

array:6 [▼ 
    "contract" => Contract {#2003 ▼ 

    - id: null 
    - actionCode: "104" 
    - productCode: "20106" 
    - created: null 
    - updated: null 
    - resumeId: null 
    - rcode1: null 
    - rcode2: null 
    - downloadId: null 
    - businessContractDetails: BusinessContractDetails {#1999 ▶} 
    - privateContractDetails: null 
    - company: Company {#2000 ▶} 
    - persons: ArrayCollection {#1998 ▶} 
    } 

"businessContractDetails" => BusinessContractDetails {#1999 ▶} 

"company" => Company {#2000 ▶} 

"contactPerson" => ContactPerson {#1987 ▶} 

"landlord" => Landlord {#1993 ▶} 

"businessRealEstate" => BusinessRealEstate {#1994 ▶} 

] 

계약 엔티티의 렌더링되는 속성 및 RCODE1 RCODE2이다. 하지만 downloadID에 대한 액세스 권한이 필요합니다.

나는
$form->get('contract')->get('downloadId')->getData(); 

을 시도하고 다음과 같은 오류 메시지가 있어요 : 아이 "downloadId"존재하지 않습니다.

제안 사항? 미리 감사드립니다!

답변

0

$form->get('contract')->getData()->getDownloadId(); 

당신이 당신의 Contract 클래스의 게터 getDownloadId이 내가 믿고있어주의하십시오

+0

아 ... 감사합니다! 그게 도움이 됐어! – Zebula

+0

제발 대답을 투표하는 것을 잊지 마세요 :) –

+0

죄송합니다, 나는 명성 포인트가 15 점 미만입니다. 나는 당신의 대답을 upvote 수 없습니다 : ( – Zebula

0

양식을 통해 기업의 가치를 액세스하지 말아야 컨트롤러. 그래도 작동 할 수 있습니다. 예를 들어 양식 유형이 contract 인 이름이 바뀌는 경우에는 좋지 않습니다.

handleRequest 뒤에 엔티티가 양식의 데이터로 채워진 양식을 작성한 엔티티에 의존 할 수 있습니다. 따라서 :

# Controller POST action 
$entity = new Contract(); // Or retrieve it from database: $em->find(Contract, $id); 
$form = $this->createForm(FormType::class, $entity)->handleRequest($request); 
echo $entity->getDownloadId(); 
관련 문제