xjermx Posted April 6, 2012 Share Posted April 6, 2012 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! Link to comment https://forums.phpfreaks.com/topic/260466-unique-validation-codeigniter-2-doctrine-2/ Share on other sites More sharing options...
scootstah Posted April 8, 2012 Share Posted April 8, 2012 The is_unique() method expects that the standard database library is loaded. Do you have it loaded? If you don't want to do that you'll need to extend the form_validation class and write your own is_unique method using doctrine. Link to comment https://forums.phpfreaks.com/topic/260466-unique-validation-codeigniter-2-doctrine-2/#findComment-1335424 Share on other sites More sharing options...
xjermx Posted April 19, 2012 Author Share Posted April 19, 2012 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 https://forums.phpfreaks.com/topic/260466-unique-validation-codeigniter-2-doctrine-2/#findComment-1338637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.