Jump to content

unique validation - CodeIgniter 2 + Doctrine 2


xjermx

Recommended Posts

I am running Doctrine 2.2.1 and CodeIgniter 2.1.0

 

I am attempting to do a simple unique validation to make sure that a field does not already exist in the database.

 

I have tried this:

$this->form_validation->set_rules('email', 'E-mail',
                 'required|valid_email|is_unique[users.email]');

 

which gives me the following output:

 

A PHP Error was encountered

 

Severity: Notice

 

Message: Undefined property: Signup_form::$db

 

Filename: libraries/Form_validation.php

 

Line Number: 954

 

 

Fatal error: Call to a member function limit() on a non-object in /../systemFolder/libraries/Form_validation.php on line 954

 

I have also tried this (cribbed directly from codeigniter's user manual, along with an email_check function):

 

$this->form_validation->set_rules('email', 'E-mail', 'callback_email_check');

 

Which gives this output:

 

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'email_index'' in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php:131 Stack trace: #0 /../applicationFolder/libraries/Doctrine/DBAL/Statement.php(131): PDOStatement->execute(NULL) #1 /../applicationFolder/libraries/Doctrine/ORM/Persisters/BasicEntityPersister.php(239): Doctrine\DBAL\Statement->execute() #2 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(896): Doctrine\ORM\Persisters\BasicEntityPersister->executeInserts() #3 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(304): Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php on line 131

 

Can anyone tell me the best/correct way to do unique validation in this setup?  Can anyone help me make either of the above methods work?  Thanks!

  • 2 weeks later...

Here is what I ended up with:

 

private function _registration_validate() {
            
             $this->form_validation->set_rules('email', 'E-mail', 
                     'required|valid_email|min_length[8]|trim|callback_email_check');
             
             return $this->form_validation->run();
            
        }

public function email_check($str)
{
	$user = $this->doctrine->em->getRepository('ORM\Dynasties2\Users')->findOneBy(array('email' => $str));
               if (isset($user)) {
                        $this->form_validation->set_message('email_check', 'This email address is already in use');
                        return FALSE;
                } else
	{
		return TRUE;
	}
}


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.