<legend id='EZwLm'><style id='EZwLm'><dir id='EZwLm'><q id='EZwLm'></q></dir></style></legend>
        <bdo id='EZwLm'></bdo><ul id='EZwLm'></ul>
    1. <tfoot id='EZwLm'></tfoot>
      1. <small id='EZwLm'></small><noframes id='EZwLm'>

        <i id='EZwLm'><tr id='EZwLm'><dt id='EZwLm'><q id='EZwLm'><span id='EZwLm'><b id='EZwLm'><form id='EZwLm'><ins id='EZwLm'></ins><ul id='EZwLm'></ul><sub id='EZwLm'></sub></form><legend id='EZwLm'></legend><bdo id='EZwLm'><pre id='EZwLm'><center id='EZwLm'></center></pre></bdo></b><th id='EZwLm'></th></span></q></dt></tr></i><div id='EZwLm'><tfoot id='EZwLm'></tfoot><dl id='EZwLm'><fieldset id='EZwLm'></fieldset></dl></div>

      2. 如何在编辑表单中使用 DoctrineModuleValidatorNoObjectExists - Zend Fram

        时间:2023-08-18
      3. <tfoot id='Hjgtf'></tfoot>
          <bdo id='Hjgtf'></bdo><ul id='Hjgtf'></ul>
                <tbody id='Hjgtf'></tbody>

                  <small id='Hjgtf'></small><noframes id='Hjgtf'>

                  <i id='Hjgtf'><tr id='Hjgtf'><dt id='Hjgtf'><q id='Hjgtf'><span id='Hjgtf'><b id='Hjgtf'><form id='Hjgtf'><ins id='Hjgtf'></ins><ul id='Hjgtf'></ul><sub id='Hjgtf'></sub></form><legend id='Hjgtf'></legend><bdo id='Hjgtf'><pre id='Hjgtf'><center id='Hjgtf'></center></pre></bdo></b><th id='Hjgtf'></th></span></q></dt></tr></i><div id='Hjgtf'><tfoot id='Hjgtf'></tfoot><dl id='Hjgtf'><fieldset id='Hjgtf'></fieldset></dl></div>
                  <legend id='Hjgtf'><style id='Hjgtf'><dir id='Hjgtf'><q id='Hjgtf'></q></dir></style></legend>
                • 本文介绍了如何在编辑表单中使用 DoctrineModuleValidatorNoObjectExists - Zend Framework 2 &amp;教义2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在也用于编辑的 Zend 表单中使用 DoctrineModuleValidatorNoObjectExists 验证器的最有效方法是什么?因为当我使用相同的表单来保存编辑的值时,这会验证对象存在和标志表单无效.

                  What is the most effective way to use DoctrineModuleValidatorNoObjectExists validator in a Zend Form that is used for editing also? Because when I use the same Form for saving edited values, this validates the Object existence and flags form is invalid.

                  推荐答案

                  几周前,我在自定义过滤器中使用辅助方法解决了同样的问题.我不确定这是否是正确的方法,但它有效.

                  Few weeks ago I resolved the same problem using a helper method in my custom filter. I am not sure if this is the correct approach but it works.

                  1. 编写一个扩展 ZendInputFilterInputFilter 的自定义输入过滤器.
                  2. 在过滤器的 init() 方法中添加通用过滤器和验证器.
                  3. 在输入过滤器中编写一个辅助方法,将学说的存在验证器附加到当前验证器链中,如下所示.
                  4. 在创建新对象时向过滤器实例添加存在验证器,编辑时使用通用过滤器实例.
                  1. Write a custom inputfilter extending ZendInputFilterInputFilter.
                  2. Add your generic filters and validators at init() method of filter.
                  3. Write a helper method in the input filter which appends doctrine's existence validator to current validator chain like below.
                  4. Add existence validator to your filter instance when creating new object, use generic filter instance when editing.

                  所以,

                  <?php
                  /**
                   * Baz filter
                   */
                  class BazFilter extends ZendInputFilterInputFilter
                  {
                  
                  /**
                   * This method will be triggered automatically when you retrive baz filter via inputfiltermanager.
                   */
                  public function init() 
                  {
                      // Define your input names, types, validators and filters as arrays
                      $this->add(array(
                          'name' => 'code',
                          'required' => true,
                          'validators' => array(),
                          'filters' => array()
                      ));
                  
                      $this->add( array(...) );
                      $this->add( array(...) );
                      // ...
                  }
                  
                  /**
                   * Appends doctrine's noobjectexists validator to validator chain only when required.
                   * 
                   * @access public
                   * @param DoctrineORMEntityRepository $repository
                   * @return endInputFilterInputFilter
                   */
                  public function appendExistenceValidator(DoctrineORMEntityRepository $repository)
                  {
                       $validatorSignature = array(
                          'name' => 'code',
                          'validators' => array(
                              array(
                                  'name' => 'DoctrineModuleValidatorNoObjectExists',
                                  'options' => array(
                                      'object_repository' => $repository,
                                      'fields' => 'code',
                                      'messages' => array( NoObjectExists::ERROR_OBJECT_FOUND => "This object with code already exists in database." )
                                  )
                              )
                          )
                      );
                      $validator = $this->getFactory()->createInput( $validatorSignature );
                      $this->add($validator);
                      return $this;
                      }
                  }
                  

                  最后,在编辑时将此输入过滤器附加到您的表单中:

                  Finally, append this inputfilter to your form when editing:

                  // $form = your form instance
                  // $filter = Bazfilter instance
                  $form->setData($postData)->setInputFilter( $filter );
                  if( $form->isValid() === false ) {
                      // ...
                  }
                  

                  创建时:

                  // $filter = bazfilter instance
                  $repository = $entityManager->getRepository('YourEntityName');
                  $filter->appendExistenceValidator( $repository ); // <-- Notice this line
                  
                  $form->setData($postData)->setInputFilter( $filter );
                  if( $form->isValid() === false ) {
                      // ...
                  }
                  

                  这篇关于如何在编辑表单中使用 DoctrineModuleValidatorNoObjectExists - Zend Framework 2 &amp;教义2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在实体表单类型中包含来自另一个实体的某些字段? 下一篇:Symfony2 - Doctrine2:跨数据库连接列抛出映射异常

                  相关文章

                    <bdo id='inkpM'></bdo><ul id='inkpM'></ul>

                  <small id='inkpM'></small><noframes id='inkpM'>

                  <legend id='inkpM'><style id='inkpM'><dir id='inkpM'><q id='inkpM'></q></dir></style></legend>
                  <tfoot id='inkpM'></tfoot>
                    1. <i id='inkpM'><tr id='inkpM'><dt id='inkpM'><q id='inkpM'><span id='inkpM'><b id='inkpM'><form id='inkpM'><ins id='inkpM'></ins><ul id='inkpM'></ul><sub id='inkpM'></sub></form><legend id='inkpM'></legend><bdo id='inkpM'><pre id='inkpM'><center id='inkpM'></center></pre></bdo></b><th id='inkpM'></th></span></q></dt></tr></i><div id='inkpM'><tfoot id='inkpM'></tfoot><dl id='inkpM'><fieldset id='inkpM'></fieldset></dl></div>