Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to extend Signup validation rules #10392

Closed
ghost opened this issue Dec 15, 2015 · 3 comments
Closed

Impossible to extend Signup validation rules #10392

ghost opened this issue Dec 15, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2015

There are Signup model file and after it, down - error that I take. If I comment the added validation rules part - everything are working. Any thoughts?


/frontend/models/SignupForm.php

<?php

namespace frontend\models;

use common\models\User;
use yii\base\Model;
use Yii;

/**
 * Signup form
 */
class SignupForm extends Model {

    public $username;
    public $email;
    public $password;

// added part
    public $user_real_name;
    public $user_last_name;
    public $user_sex;
    public $user_birth_date;
    public $user_country;
    public $user_area;
    public $user_city;
    public $user_time_zone;
    public $user_languages;
    public $user_messengers;
    public $user_secret_question;
    public $user_secret_question_answer;

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            ['username', 'filter', 'filter' => 'trim'],
            ['username', 'required'],
            ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
            ['username', 'string', 'min' => 2, 'max' => 255],
            ['email', 'filter', 'filter' => 'trim'],
            ['email', 'required'],
            ['email', 'email'],
            ['email', 'string', 'max' => 255],
            ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
            ['password', 'required'],
            ['password', 'string', 'min' => 8],
// added part
            ['user_real_name', 'filter', 'filter' => 'trim'],
            ['user_real_name', 'requed'],
            ['user_real_name', 'string', 'max' => 32],
            ['user_last_name', 'filter', 'filter' => 'trim'],
            ['user_last_name', 'requed'],
            ['user_last_name', 'string', 'max' => 32],
            ['user_sex', 'requed'],
            ['user_birth_date', ['from' => 1900, 'to' => 2010], 'date'],
            ['user_country', 'requed'],
            ['user_area', 'filter', 'filter' => 'trim'],
            ['user_area', 'string', 'max' => 32],
            ['user_city', 'filter', 'filter' => 'trim'],
            ['user_city', 'requed'],
            ['user_city', 'string', 'max' => 32],
            ['user_time_zone', 'requed'],
            ['user_languages', 'filter', 'filter' => 'trim'],
            ['user_messengers', 'filter', 'filter' => 'trim'],
            ['user_secret_question', 'requed'],
            ['user_secret_question_answer', 'requed']
        ];
    }

    /**
     * Signs user up.
     *
     * @return User|null the saved model or null if saving fails
     */
    public function signup() {
        if ($this->validate()) {
            $user = new User();
            $user->username = $this->username;
            $user->email = $this->email;
            $user->user_real_name = $this->user_real_name;
            $user->user_last_name = $this->user_last_name;
            $user->user_sex = $this->user_sex;
            $user->user_birth_date = $this->user_birth_date;
            $user->user_country = $this->user_country;
            $user->user_area = $this->user_area;
            $user->user_city = $this->user_city;
            $user->user_time_zone = $this->user_time_zone;
            $user->user_languages = $this->user_languages;
            $user->user_messengers = $this->user_messengers;
            $user->user_secret_question = $this->user_secret_question;
            $user->user_secret_question_answer = $this->user_secret_question_answer;
            $user->setPassword($this->password);
            $user->generateAuthKey();
            if ($user->save()) {
                return $user;
            }
        }
        return null;

--------------------------------------------------------------------------- end of file.

Here the error:

PHP User Error – yii\base\ErrorException

Exception 'ReflectionException' with message 'Class requed does not exist' 

in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/di/Container.php:415

Stack trace:
#0 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/di/Container.php(415): ReflectionClass->__construct('requed')
#1 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/di/Container.php(358): yii\di\Container->getDependencies('requed')
#2 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('requed', Array, Array)
#3 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('requed', Array, Array)
#4 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/validators/Validator.php(206): yii\BaseYii::createObject(Array)
#5 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Model.php(441): yii\validators\Validator::createValidator('requed', Object(frontend\models\SignupForm), Array, Array)
#6 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Model.php(405): yii\base\Model->createValidators()
#7 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Model.php(185): yii\base\Model->getValidators()
#8 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Model.php(768): yii\base\Model->scenarios()
#9 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/widgets/ActiveField.php(688): yii\base\Model->activeAttributes()
#10 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/widgets/ActiveField.php(210): yii\widgets\ActiveField->getClientOptions()
#11 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/widgets/ActiveField.php(200): yii\widgets\ActiveField->begin()
#12 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2-bootstrap/ActiveField.php(188): yii\widgets\ActiveField->render(NULL)
#13 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/widgets/ActiveField.php(156): yii\bootstrap\ActiveField->render()
#14 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/frontend/views/site/signup.php(22): yii\widgets\ActiveField->__toString()
#15 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php(325): require('/home/kerych74/...')
#16 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php(247): yii\base\View->renderPhpFile('/home/kerych74/...', Array)
#17 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php(149): yii\base\View->renderFile('/home/kerych74/...', Array, Object(frontend\controllers\SiteController))
#18 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Controller.php(371): yii\base\View->render('signup', Array, Object(frontend\controllers\SiteController))
#19 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/frontend/controllers/SiteController.php(162): yii\base\Controller->render('signup', Array)
#20 [internal function]: frontend\controllers\SiteController->actionSignup()
#21 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#22 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#23 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('signup', Array)
#24 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('site/signup', Array)
#25 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#26 /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/frontend/web/index.php(18): yii\base\Application->run()
#27 {main}
1. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/ErrorHandler.php at line 299
290291292293294295296297298299300301302303304305306307308    /**
     * Converts an exception into a PHP error.
     *
     * This method can be used to convert exceptions inside of methods like `__toString()`
     * to PHP errors because exceptions cannot be thrown inside of them.
     * @param \Exception $exception the exception to convert to a PHP error.
     */
    public static function convertExceptionToError($exception)
    {
        trigger_error(static::convertExceptionToString($exception), E_USER_ERROR);
    }

    /**
     * Converts an exception into a simple string.
     * @param \Exception $exception the exception being converted
     * @return string the string representation of the exception.
     */
    public static function convertExceptionToString($exception)
    {
2. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/widgets/ActiveField.php at line 158 – yii\base\ErrorHandler::convertExceptionToError()
3. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php at line 22 – yii\widgets\ActiveField::__toString()
4. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php at line 325 – unknown()
5. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php at line 247 – yii\base\View::renderPhpFile()
6. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/View.php at line 149 – yii\base\View::renderFile()
7. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Controller.php at line 371 – yii\base\View::render()
8. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/frontend/controllers/SiteController.php at line 162 – yii\base\Controller::render()
156157158159160161162163164165166167168                }
            }
        }

        return $this->render('signup', [
            'model' => $model,
        ]);
    }

    /**
     * Requests password reset.
     *
     * @return mixed
9. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – frontend\controllers\SiteController::actionSignup()
10. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – call_user_func_array:{/home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/InlineAction.php:55}()
11. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Controller.php at line 151 – yii\base\InlineAction::runWithParams()
12. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Module.php at line 455 – yii\base\Controller::runAction()
13. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/web/Application.php at line 84 – yii\base\Module::runAction()
14. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/vendor/yiisoft/yii2/base/Application.php at line 375 – yii\web\Application::handleRequest()
15. in /home/kerych74/rubystack-2.2.3-3/apache2/htdocs/mafia-yii2/frontend/web/index.php at line 18 – yii\base\Application::run()
12131415161718    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();
--------------------------------------------------------------------------------
@cebe
Copy link
Member

cebe commented Dec 15, 2015

['user_sex', 'requed'],

typo: requed -> required

@cebe cebe closed this as completed Dec 15, 2015
@cebe
Copy link
Member

cebe commented Dec 15, 2015

Also please try to format your message using markdown next time: https://guides.github.com/features/mastering-markdown/

@ghost
Copy link
Author

ghost commented Dec 17, 2015

thanks!

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

No branches or pull requests

1 participant