2012-05-18 2 views
0

나는 하우스 양식을 작성하고 이미지 양식을 그 안에 포함하려고합니다. 나는 튜토리얼 http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms을 따른다.Symfony - 삽입 양식을 추가하는 방법은 무엇입니까?

houses: 
    actAs: { Timestampable: ~ } 
    columns: 
    name: { type: string(255), notnull: true } 
    description: { type: string(5000), notnull: true } 

images: 
    actAs: { Timestampable: ~ } 
    columns: 
    url: { type: string(255), notnull: true } 
    id_house: { type: integer, notnull: true } 
    relations: 
    houses: { local: id_house, foreign: id, foreignAlias: HousesImg} 

및 코드 : 예상대로

//lib/form/doctrine/ImagesCollectionForm 

class ImagesCollectionForm extends sfForm 
{ 
    public function configure() 
    { 
    if(!$house= $this->getOption('house')) 
    { 
     throw new InvalidArgumentException('You must provide an house'); 
    } 

    for ($i = 0; $i < $this->getOption('size',2); $i++) 
    { 
     $images = new images(); 
     $images->house = $house; 

     $form = new imagesForm($images); 
     $this->embedForm($i, $form); 
    } 
    } 
} 

//lib/form/doctrine/housesForm.class.php 

public function configure() 
{ 
    $form = new ImagesCollectionForm(null, array('house' => $this->getObject(),'size'=>2)); 
    $this->embedForm('images', $form); 
} 

필드가 표시됩니다

나는 다음과 같은 스키마를 가지고있다. 그러나 저장 버튼을 누르면 빈 페이지가 나타나고 데이터는 데이터베이스에 저장되지 않습니다.

+0

dev crontroler ('frontend_dev.php')를 사용하여 오류를 보았습니까? – j0k

+0

오타가 없습니까? $ images-> houses = $ house;에 대한 $ images-> house = $ house;' –

+0

문제를 발견했습니다. imagesForm.class.php에서 $ this-> useFields (...)를 추가하지 않았으며 house_id 필드에 문제가있었습니다. 이제 효과가 있습니다. – july

답변

0

사용은

그래서 u는 $ images-> 집 = $ 하우스를 변경해야하는 관계 이름을 보면 너무 기본 심포니에 의해 제품 와 이미지의 관계에 별명을 지정하지 않은; $ images-> houses = $ house까지; 또는 u가 관계 별칭을 설정할 수 있습니다.

희망이 도움이 될 것입니다.

관련 문제