• <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

        Zend_Validate: Db_NoRecordExists with Doctrine(Zend_Validate: Db_NoRecordExists with Doctrine)

          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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                      <tbody id='mtvHR'></tbody>

                        <tfoot id='mtvHR'></tfoot>
                          <bdo id='mtvHR'></bdo><ul id='mtvHR'></ul>
                        • <legend id='mtvHR'><style id='mtvHR'><dir id='mtvHR'><q id='mtvHR'></q></dir></style></legend>

                        • <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'>