Gebruik:

Je [u]moet[/u] een model maken met minimaal het volgende:

[code]

<?php
class Users extends Zend_Db_Table
{
  protected $_name = 'users';
  protected $_primary = 'user_id';
}
[/code]

($_primary is natuurlijk niet nodig maar ik gebruik ID niet als mijn primary key)

het form element:
[code]
<?php
$this->addElement('text', 'name', array(
  'decorators' => $this->_standardElementDecorator,
  'label' => 'Desired Username:',
  'Validators' => array(
    array('StringLength', false, array(5,20)),
    array('UniqueField', false, array('users', 'username')),
  ),
  'required' => true
));
[/code]

specifiek deze regel:
[code]array('UniqueField', false, array('users', 'username'))[/code]

UniqueField = naam van validator.
users = naam van model
username = naam van veld

en de validator:
ps. Ja ik heb hem gewoon in mijn Zend/Validate folder staan :)
[code]
<?php
 
class Zend_Validate_UniqueField extends Zend_Validate_Abstract 
{ 
    /** 
     * @var String 
     */ 
    const NOT_UNIQUE = 'error'; 
 
    /** 
     * @var String 
     */ 
    protected $_modelName = 'Users'; 
 
    /** 
     * @var String 
     */ 
    protected $_fieldName = 'username'; 
 
    /** 
     * @var array 
     */ 
    protected $_messageTemplates = array( 
    	self::NOT_UNIQUE => "The data given is not unique."
    ); 
 
    /** 
     * Sets validator options 
     * 
     * @param  string $modelName 
     * @param  string $fieldName 
     * @return void 
     */ 
    public function __construct($modelName = '', $fieldName = '') 
    { 
        $this->setModelName($modelName); 
        $this->setFieldName($fieldName); 
    } 
 
    /** 
     * Defined by Zend_Validate_Interface 
     * 
     * Returns true if and only if the email address is found to NOT have a match in the fieldname in the model specified 
     * 
     * @param Array $value 
     * @param Array $request 
     * @return boolean 
     */ 
    public function isValid($value, $request = null) 
    { 
        // Set the value 
        $value = (string) $value; 
        $this->_setValue($value); 
 		
        // Get our model and do a search for that username 
        $table = new $this->_modelName; 
        $result = $table->fetchAll($table->select()->where("$this->_fieldName = '$value'"))->toArray(); 
		
        // Check to see if we got any results 
        if (count($result) == 0) { 
            return true; 
        } 
 	
        $this->_error(self::NOT_UNIQUE); 
        return false; 
    } 
 
    /** 
     * Set the model name. 
     * 
     * @param string $modelName 
     * @return Zend_Validate_UniqueUsername Provides a fluent interface 
     */ 
    public function setModelName($modelName) 
    { 
        $this->_modelName = $modelName; 
        return $this; 
    } 
 
    /** 
     * Set the field name. 
     * 
     * @param string $fieldName 
     * @return Zend_Validate_UniqueUsername Provides a fluent interface 
     */ 
    public function setFieldName($fieldName) 
    { 
        $this->_fieldName = $fieldName; 
 
        return $this; 
    } 
} 
[/code]

Ik hoop dat iemand hier iets aan heeft.

