<legend id='MK9kg'><style id='MK9kg'><dir id='MK9kg'><q id='MK9kg'></q></dir></style></legend>
      <bdo id='MK9kg'></bdo><ul id='MK9kg'></ul>

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

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

        <tfoot id='MK9kg'></tfoot>

        Zend_Validate: Db_NoRecordExists with Doctrine

        时间:2023-10-02
        <i id='p0rWO'><tr id='p0rWO'><dt id='p0rWO'><q id='p0rWO'><span id='p0rWO'><b id='p0rWO'><form id='p0rWO'><ins id='p0rWO'></ins><ul id='p0rWO'></ul><sub id='p0rWO'></sub></form><legend id='p0rWO'></legend><bdo id='p0rWO'><pre id='p0rWO'><center id='p0rWO'></center></pre></bdo></b><th id='p0rWO'></th></span></q></dt></tr></i><div id='p0rWO'><tfoot id='p0rWO'></tfoot><dl id='p0rWO'><fieldset id='p0rWO'></fieldset></dl></div>
      1. <tfoot id='p0rWO'></tfoot>

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

      2. <legend id='p0rWO'><style id='p0rWO'><dir id='p0rWO'><q id='p0rWO'></q></dir></style></legend>

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

                    <tbody id='p0rWO'></tbody>
                1. 本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

                  相关文章

                  最新文章

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

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

                  1. <small id='KO0JU'></small><noframes id='KO0JU'>