Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

EMongoUniqueValidator and ClassName doesn't work #76

Open
aUbilla opened this issue Jun 27, 2014 · 3 comments
Open

EMongoUniqueValidator and ClassName doesn't work #76

aUbilla opened this issue Jun 27, 2014 · 3 comments

Comments

@aUbilla
Copy link

aUbilla commented Jun 27, 2014

Hello, congrats and thank you for EMongoUniqueValidator script!, I am Andrés from Chile, I have implemented YiiMongoDbSuite in a proyect for study and learn to MongoDB, but I have a little problem, I need validate field "Email" of my document but doesn't work, My form "RegistroForm" extends from CFormModel and my rule is:
array('email', 'ext.YiiMongoDbSuite.extra.EMongoUniqueValidator', 'className' => 'Usuario'),

But in the webpage appears this error: The property "EMongoUniqueValidator"."className" has not defined.

Because the form "RegistroForm" is not a Model (EMongoDocument), the Model is "Usuario". how can I resolve this?, can any one help me?

@it-conception
Copy link

Hello, EMongoUniqueValidator in this project doesn't support the className you should extend your class "RegistroForm" of "Usuario" or try to use this class : https://github.com/Blizzke/yii-mongodb-suite/blob/master/validators/CMongoUniqueValidator.php

@aUbilla
Copy link
Author

aUbilla commented Jun 30, 2014

Hello again, thank you for you response, but doesn't work yet, I have implemented the extension CMongoUniqueValidator like this:
array('email', 'ext.YiiMongoDbSuite.extra.CMongoUniqueValidator', 'className' => 'Usuario', 'message' => 'Errooooooooor!')

But I have this error: "Usuario y sus behaviors no tienen un método o closure llamado "exists"."

Can you help me? What I'm doing wrong?

@it-conception
Copy link

if you would use this class, you must copy entire of project.
But I suggest you to extend your class "RegistroForm" of "Usuario". Exemple

<?php

class RegistrationForm extends Usuario {
    public $verifyPassword;
    public $verifyCode;

    public function rules() {
        $rules = array(
            array('username, password, verifyPassword, email', 'required'),
            array('username', 'filter', 'filter'=>'strtolower'),
            array('username', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect username (length between 3 and 20 characters).")),
            array('password', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
            array('email', 'email'),
            array('username', 'EMongoUniqueValidator', 'message' => UserModule::t("This user's name already exists.")),
            array('email', 'EMongoUniqueValidator', 'message' => UserModule::t("This user's email address already exists.")),
            array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")),
            array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),
        );
        if (!(isset($_POST['ajax']) && $_POST['ajax']==='registration-form')) {
            array_push($rules,array('verifyCode', 'captcha', 'allowEmpty'=>!UserModule::doCaptcha('registration')));
        }

        array_push($rules,array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")));
        return $rules;
    }

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants