현재 문제가 지속되어 터널 끝 부분에서 불빛을 찾지 못하는 것 같습니다.데이터를 저장하는 형식이 올바르지 않습니다.
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;
}
잘못된 데이터는 무엇을 의미합니까? 나는 "특별"검증을 볼 수 없다. – CSchulz
삽입 된 양식에 제약이 있습니다. 마찬가지로 일부 필드는 3보다 우수하지 않은 경우 false로 설정해야합니다. 선물이 표시되면 오류가 올바르게 표시됩니다 (즉, "msg.update_failed_see_errors", 즉 양식이 유효하지 않지만 데이터가 데이터베이스에서 변경되었음을 의미 함) – Maravedis
"msg.changes_saved"라는 플래시 메시지가 표시됩니다. ? – CSchulz