• <legend id='USW3Q'><style id='USW3Q'><dir id='USW3Q'><q id='USW3Q'></q></dir></style></legend>

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

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

      1. Zend_Validate: Db_NoRecordExists with Doctrine

        时间:2023-05-30

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

                  <tbody id='I4SAT'></tbody>

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

                  本文介绍了Zend_Validate: Db_NoRecordExists with Doctrine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您好,我正在尝试使用 Zend_Validate 和 Zend_Form 验证表单.

                  Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form.

                  我的元素:

                  $this->addElement('text', 'username', array(
                      'validators' => array(
                          array(
                              'validator' => 'Db_NoRecordExists',
                              'options' => array('user','username')
                              )
                      )
                  ));
                  

                  因为我使用 Doctrine 来处理我的数据库,Zend_Validate 错过了一个 DbAdapter.我可以在选项中传递一个适配器,但是我如何结合 Zend_Db_Adapter_Abstract 和 Doctrine?

                  For I use Doctrine to handle my database, Zend_Validate misses a DbAdapter. I could pass an adapter in the options, but how do I combine Zend_Db_Adapter_Abstract and Doctrine?

                  是否有更简单的方法来完成这项工作?

                  Is there maybe an easyer way to get this done?

                  谢谢!

                  推荐答案

                  用自己的验证器解决了:

                  Solved it with an own Validator:

                  <?php
                  
                  class Validator_NoRecordExists extends Zend_Validate_Abstract
                  {
                      private $_table;
                      private $_field;
                  
                      const OK = '';
                  
                      protected $_messageTemplates = array(
                          self::OK => "'%value%' ist bereits in der Datenbank"
                      );
                  
                      public function __construct($table, $field) {
                          if(is_null(Doctrine::getTable($table)))
                              return null;
                  
                          if(!Doctrine::getTable($table)->hasColumn($field))
                              return null;
                  
                          $this->_table = Doctrine::getTable($table);
                          $this->_field = $field;
                      }
                  
                      public function isValid($value)
                      {
                          $this->_setValue($value);
                  
                          $funcName = 'findBy' . $this->_field;
                  
                          if(count($this->_table->$funcName($value))>0) {
                              $this->_error();
                              return false;
                          }
                  
                          return true;
                      }
                  }
                  

                  这样使用:

                  $this->addElement('text', 'username', array(
                      'validators' => array(
                          array(
                              'validator' => new Validator_NoRecordExists('User','username')
                              )
                      )
                  ));
                  

                  这篇关于Zend_Validate: Db_NoRecordExists with Doctrine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:有一个 BaseController 并使所有控制器都扩展该类是个好主意吗? 下一篇:转发 Zend_Mail_Message

                  相关文章

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

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