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@address.com' 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!

Link to comment
Share on other sites

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


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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