I
I
Ivan Yakushenko2016-07-16 14:54:26
Yii
Ivan Yakushenko, 2016-07-16 14:54:26

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}

The website has the following error:
Getting unknown property: yii\web\Application::app

in D:\OpenServer\domains\yii2sp\models\User.php
public function generateAuthKey(){
        $this->auth_key = Yii::$app->app->security->generateRandomString();
    }

in D:\OpenServer\domains\yii2sp\models\SignupForm.php
$user->generateAuthKey();
in D:\OpenServer\domains\yii2sp\controllers\SiteController.php
if ($user = $model->signup()) {
in D:\OpenServer\domains\yii2sp\web\index.php
(new yii\web\Application($config))->run();

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nikita, 2016-07-16
@kshnkvn

SingupForm has something like this in the validation rules.
Find something to change?

D
Dmitry Kim, 2016-07-16
@kimono

Check that the User is in the common/models/ path (they may differ in basic and advanced), and that User has this namespace specified.

M
Maxim Timofeev, 2016-07-16
@webinar

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

S
Slava Vitrenko, 2016-07-17
@bagiroff777

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 question

Ask a Question

731 491 924 answers to any question