2014-10-23 1 views
0

현재 문제가 지속되어 터널 끝 부분에서 불빛을 찾지 못하는 것 같습니다.데이터를 저장하는 형식이 올바르지 않습니다.

public function settingsAction(Request $request) 
{ 
    $org = $this->getUser()->getOrganisation(); 
    $form = $this->createForm(new OrgSettingsType(), $org); 

    $form->handleRequest($request); 
    if ($form->isSubmitted() && $form->isValid()) 
    { 
      $dm = $this->get('doctrine_mongodb')->getManager(); 
      $dm->persist($this->getUser()->getOrganisation()); 
      $dm->flush(); 
      $this->get('session')->getFlashBag()->add('success', 'msg.changes_saved'); 
      return $this->redirect($this->generateUrl('metacloud_account_organisation_settings')); 
    } 

    if ($form->isSubmitted()) 
    { 
     $this->get('session')->getFlashBag()->add('danger', 'msg.update_failed_see_errors'); 
    } 

    return $this->render('MetaCloudAccountBundle:Organisation:settings.html.twig', array('form' => $form->createView())); 
} 

양식 정말 더 복잡한 것이 아니라, 그것은 두 가지 수준의 양식입니다 :

나는 간단한 컨트롤러 기능의 종류가

class OrgSettingsType extends AbstractType 
{ 
public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder->add('groups', 'collection', array(
     'type' => 'text', 
     'allow_add' => true, 
     'options' => array(
      'label' => false 
     ) 
    )); 

    $builder->add('cloudAccounts', 'cloud_account', array(
    )); 

    $builder->add('settings', new OrganisationConfigType()); 
} 

public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'MetaCloud\DataBundle\Document\Organisation', 
     'cascade_validation' => true, 
     'validation_groups' => array('account_edit', 'Default') 
    )); 
} 

public function getName() 
{ 
    return 'org_config'; 
} 
} 

OrganisationConfigType 형태가 간단하다 충분하고 문서의 OrganisationConfig에 연결됩니다. 여기서 제약 조건은 주석 형식으로 선언됩니다.

문제는 양식을 제출할 때 데이터가 올바르지 않고 양식에 그렇게 되어도 여전히 데이터베이스에 수정 사항이 유지된다는 것입니다. 이 문제에 대한 나의 이해는 양식 자체만으로는 어떤 데이터도 유지되지 않고 데이터를 내가 설정 한 제약 조건 주석과 비교한다는 것입니다. 질문을 홍수로 내 코드를 모두 표시하지 않으려 고하지만, 더 자세한 정보가 필요하면 질문하고 편집 해 보겠습니다.

고마워요.

편집 : 누군가 내 엔티티 코드를 요청했습니다. 관련없는 getters 및 setter없이 게시합니다.

/** 
* @MongoDB\Document(collection="societe", repositoryClass="MetaCloud\DataBundle\Repository\OrganisationRepository") 
* @MongoDB\HasLifecycleCallbacks 
* @Unique("email") 
*/ 
class Organisation 
{ 

/** 
* @MongoDB\Id(strategy="AUTO", name="_id") 
*/ 
protected $id; 

/** 
* @MongoDB\String(name="nom") 
* 
* @Assert\NotNull(message="error name") 
*/ 
protected $name; 

/** 
* @MongoDB\String(name="siret", nullable=true) 
* 
* 
*/ 
protected $number; 

/** 
* @MongoDB\String(name="nomRep") 
* 
* @Assert\NotNull(
*  message = "contact last name cant be null" 
* ) 
*/ 
protected $contactLastName; 

/** 
* @MongoDB\String(name="prenomRep") 
* 
* @Assert\NotNull(message="error contact first name") 
*/ 
protected $contactFirstName; 

/** 
* @MongoDB\String(name="titreRep", nullable=true) 
*/ 
protected $contactTitle; 

/** 
* @MongoDB\String(name="civilite") 
* 
* @Assert\NotNull(message="civilite is null") 
*/ 
protected $contactHonorific; 

/** 
* @MongoDB\String(name="email") 
* 
* @Assert\NotNull() 
* @Assert\Email() 
*/ 
protected $email; 

/** 
* @MongoDB\String(name="emailadmin", nullable = true) 
* 
* @Assert\Email() 
*/ 
protected $emailAdmin = ""; 

/** 
* @MongoDB\String(name="telephone") 
* 
* @Assert\NotNull 
*/ 
protected $phone; 

/** 
* @MongoDB\Int(name="maxutilisateurs") 
* 
* @Assert\NotNull(groups={"account_edit"}) 
* @Assert\Range(min=1, groups={"account_edit"}) 
* @Assert\NotNull() 
*/ 
protected $maxUsers; 

/** 
* @MongoDB\Int(name="restutilisateurs", nullable=true) 
*/ 
protected $remainingUsers; 

/** 
* @MongoDB\EmbedOne(targetDocument="Contract", name="contract", nullable=true) 
*/ 
protected $contract; 

/** 
* @MongoDB\String(name="datecreated") 
*/ 
protected $createdAt; 

/** 
* @MongoDB\Date(name="datedeleted", nullable=true) 
*/ 
protected $deletedAt; 


/** 
* @MongoDB\EmbedOne(targetDocument="Address", name="adresse") 
* 
* @Assert\NotNull() 
* @Assert\Valid() 
*/ 
protected $address; 

/** 
* @MongoDB\Collection(name="groupes", nullable=true) 
* 
*/ 
protected $groups = array(); 

/** 
* @MongoDB\EmbedOne(targetDocument="Administrator", name="administrateur") 
*/ 
protected $administrator; 

/** 
* @MongoDB\ReferenceOne(targetDocument="User", name="mappedadmin") 
* 
* @Gedmo\ReferenceIntegrity("nullify") 
*/ 
protected $mappedAdmin; 

/** 
* @MongoDB\EmbedOne(targetDocument="OrganisationConfig", name="configpublique", nullable=true) 
*/ 
protected $settings; 

/** 
* @MongoDB\Collection(name="cloudstockages", nullable=true) 
* 
* @Assert\Count(min=1, groups={"account_edit"}) 
*/ 
protected $cloudAccounts = array(); 

/** 
* @MongoDB\ReferenceMany(targetDocument="User", mappedBy="organisation", nullable=true) 
* 
* @Gedmo\ReferenceIntegrity("nullify") 
*/ 
protected $users; 


/** 
* @MongoDB\ReferenceMany(targetDocument="SecurityCode", mappedBy="organisation", nullable=true) 
* 
* @Gedmo\ReferenceIntegrity("nullify") 
*/ 
protected $invites; 

/** 
* @MongoDB\ReferenceMany(targetDocument="Organisation", mappedBy="integrator", name="organisations", nullable=true) 
*/ 
protected $organisations; 

/** 
* @MongoDB\ReferenceOne(targetDocument="Organisation", inversedBy="organisations", name="integrator", simple="true") 
*/ 
protected $integrator; 


/** 
* @MongoDB\Field(type="boolean", name="anintegrator") 
* 
*/ 
protected $anIntegrator; 

/** 
* Determine if there are enough accounts to provide Confidentiality 
* 
* @Assert\True(
* message = "org_not_enough_accounts_for_confidentiality", 
* groups={"account_edit"} 
*) 
* 
* @return bool 
*/ 
public function isEnoughCloudAccountsForConfidentiality() 
{ 
    if(null === $this->getSettings()) { 
     return true; 
    } 

    if('NO' != $this->getSettings()->getIntegrity() && null !== $this->getSettings()->getIntegrity()) { 
     // validate if getIntegrity is selected as it has a higher level validation rule 
     return true; 
    } 

    if('NO' != $this->getSettings()->getConfidentiality() && null !== $this->getSettings()->getConfidentiality()) { 
     return count($this->cloudAccounts) >= 1; 
    } 

    return true; 
} 
/** 
* Determine if there are enough accounts to provide Integrity 
* 
* @Assert\True(
* message = "org_not_enough_accounts_for_integrity", 
* groups={"account_edit"} 
*) 
* 
* @return bool 
*/ 
public function isEnoughCloudAccountsForIntegrity() 
{ 
    if(null === $this->getSettings()) { 
     return true; 
    } 

    if('NO' != $this->getSettings()->getIntegrity() && null !== $this->getSettings()->getIntegrity()) { 
     return count($this->cloudAccounts) >= 2; 
    } 

    return true; 
} 
+0

잘못된 데이터는 무엇을 의미합니까? 나는 "특별"검증을 볼 수 없다. – CSchulz

+0

삽입 된 양식에 제약이 있습니다. 마찬가지로 일부 필드는 3보다 우수하지 않은 경우 false로 설정해야합니다. 선물이 표시되면 오류가 올바르게 표시됩니다 (즉, "msg.update_failed_see_errors", 즉 양식이 유효하지 않지만 데이터가 데이터베이스에서 변경되었음을 의미 함) – Maravedis

+0

"msg.changes_saved"라는 플래시 메시지가 표시됩니다. ? – CSchulz

답변

0

문제점을 발견했습니다. 사실 Symfony 유효성 검사기 서비스 만 으로 데이터는 유효하지 않지만 데이터베이스의 수정 된 엔티티는 새로 고치지 않습니다.

if ($form->isSubmitted()) 
{ 
    $dm->refresh($org); 
    $this->get('session')->getFlashBag()->add('danger', 'msg.update_failed_see_errors'); 
} 

사람이 같은 문제가있는 경우

가 흥미 소스를 여기에서 찾을 수 있습니다 :

Google groups discussion about the problem Ticket on the subject for symfony2

내가해야 할 일을했을 모든 것을 작동하게하기 위해 폼에 관련된 객체를 새로했다
0

내가이 문제를 발견했다고 생각합니다. 당신은이 작업을 수행 :

$dm->persist($this->getUser()->getOrganisation()); 

당신은 그렇게해야합니다

$dm->persist($org); 

실제로 검증에서이 변수 $ 조직에 연결되어, 객체에 대한 참조가 아니라, 나는 생각한다. 시도해주십시오 :)

+0

시도해 보았습니다. 문제는 내가이 조건 코드를 입력하지 않았기 때문에 (내 양식 잘못된 것입니다.) 문제가이 수준에 있다고 생각하지 않습니다. 시간 내 주셔서 감사합니다 :) – Maravedis

+0

예, 참으로 바보 같았습니다. 우리가 무슨 일이 일어나는지 이해하기 위해서 : 당신은 당신의 위험 flashbag를 얻고, 전체 객체는 데이터베이스 (하위 객체 OrganisationConfig뿐 아니라)에 보존됩니다. – frankie567

+0

전체 개체가 저장되었습니다. 방금 검사했습니다. – Maravedis

0

아마도 컨트롤러의 지속 작업은 양식 자체와 아무 관련이 없습니다. 양식은

$org = $this->getUser()->getOrganisation();

가 'MetaCloud \ DataBundle \ 문서 \기구'형식의 개체를 반환, 당신은 확신, data_class을 'MetaCloud \ DataBundle \ 문서 \기구'는 기본? 명확하게하기 위해 엔티티 코드를 게시하십시오.

편집 : 또한 데이터를 보존하기 전에 $org = $form->getData(); 을 추가하십시오.

+0

getOrganisation()이 올바른 종류의 객체를 반환한다고 확신합니다.이 구조체의 다른 문서가 없으므로 양식을 작성할 수 없습니다. getter는 오류를 반환합니다. 엔티티 코드가 너무 길어서 내가 할 수있는 일을 볼 수 있습니다. – Maravedis