Answer the question
In order to leave comments, you need to log in
What causes an error when trying to register a user in Yii2?
Yii2 basic version 2.0.9 took the SignupForm.php and signup.php files from the advanced version, corrected all dependencies, added the missing functions to SiteController.php and User.php. After clicking the "register" button, an error appears in the debugger:
exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: yii\web\Application::app' in D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\base\Component.php:143
Stack trace:
#0 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\di\ServiceLocator.php(73): yii\base\Component->__get('app')
#1 D:\OpenServer\domains\yii2sp\ models\User.php(79): yii\di\ServiceLocator->__get('app')
#2 D:\OpenServer\domains\yii2sp\models\SignupForm.php(63): app\models\User->generateAuthKey ()
#3 D:\OpenServer\domains\yii2sp\controllers\SiteController.php(131): app\models\SignupForm->signup()
#4 [internal function]: app\controllers\SiteController->actionSignup()
#5 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#6 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\base \Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#7 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\base\Module.php(454): yii\base\Controller ->runAction('signup', Array)
#8 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\web\Application.php(87): yii\base\Module->runAction('site/signup' , Array)
#9 D:\OpenServer\domains\yii2sp\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#10 D :\OpenServer\domains\yii2sp\web\index.php(12): yii\base\Application->run()
#11 {main}
Getting unknown property: yii\web\Application::app
public function generateAuthKey(){
$this->auth_key = Yii::$app->app->security->generateRandomString();
}
$user->generateAuthKey();
if ($user = $model->signup()) {
(new yii\web\Application($config))->run();
Answer the question
In order to leave comments, you need to log in
SingupForm has something like this in the validation rules.
Find something to change?
Check that the User is in the common/models/ path (they may differ in basic and advanced), and that User has this namespace specified.
Class '\common\models\User' does not exist for you. Correct namespace in SignupForm. The common folder exists in advanced, but it doesn't exist in basic
You clearly indicated in the stack trace where the error is - Yii::$app-> app-> security->generateRandomString();
Bold - delete.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question