Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2,登录后,但不更改为注销。以及如何在登录后从数据库中获取Id_Php_Login_Yii2_Yii Components - Fatal编程技术网

Php Yii2,登录后,但不更改为注销。以及如何在登录后从数据库中获取Id

Php Yii2,登录后,但不更改为注销。以及如何在登录后从数据库中获取Id,php,login,yii2,yii-components,Php,Login,Yii2,Yii Components,我已经尝试了从一步一步的教程 登录成功。但登录标签仍带有登录标签,不能更改为注销和用户名 我不懂怎么读 1. Yii::t('app','Nama Admin') in Admin class which implement IdentityInterface ? 2. Where is Yii::$app->user->isGuest in main.php ? or how to read this ? 下面是代码 Admin是实现IdentityInterface的用户类

我已经尝试了从一步一步的教程

登录成功。但登录标签仍带有登录标签,不能更改为注销和用户名

我不懂怎么读

1. Yii::t('app','Nama Admin') in Admin class which implement IdentityInterface ?

2. Where is Yii::$app->user->isGuest in main.php ? or how to read this ?
下面是代码

Admin是实现IdentityInterface的用户类

 public static function tableName()
    {
        return 'admin';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['namaAdmin', 'username', 'password', 'authKey'], 'required'],
            [['namaAdmin', 'password'], 'string', 'max' => 20],
            [['username'], 'string', 'max' => 25],
            [['authKey'], 'string', 'max' => 50],
        ];
    }

public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'namaAdmin' => Yii::t('app','Nama Admin'),
            'username' => Yii::t('app','Username'),
            'password' => Yii::t('app','Password'),
            'authKey' => Yii::t('app','Auth Key'),
        ];
    }
有些方法和视频是一样的

model>Login.php上的一些函数

SiteController上的登录和注销操作

在main.php上标记登录/注销

Yii::$app->user->isGuest?(
['label'=>'Login','url'=>['/site/Login']]
) : (
“
  • ” .Html::beginForm(['/site/logout'],'post',['class'=>'navbar form'])) .Html::submitButton( '注销('.Yii::$app->user->identity->username.'), ['class'=>'btn-btn-link'] ) .Html::endForm() “
  • ” )
    config/web.php
    中将
    用户
    数组更改为以下内容:

    'user' => [
      'identityClass' => 'app\models\Admin',
      'enableAutoLogin' => true,
    ]
    

    config/web.php
    中将
    user
    数组更改为以下内容:

    'user' => [
      'identityClass' => 'app\models\Admin',
      'enableAutoLogin' => true,
    ]
    

    显示您的
    var\u转储(Yii::$app->user->isGuest)请在登录后。如果是来宾。。yii::$app->user->id返回false/0,否则返回false;用户id;)嗯,加上你必须在主/主本地区告诉我你使用的是哪一类。。在组件中,让用户定义..显示您的
    var\u转储(Yii::$app->user->isGuest)请在登录后。如果是来宾。。yii::$app->user->id返回false/0,否则返回false;用户id;)嗯,加上你必须在主/主本地区告诉我你使用的是哪一类。。在组件中,具有用户定义的。。
    
    Yii::$app->user->isGuest ? (
                    ['label' => 'Login', 'url' => ['/site/login']]
                ) : (
                    '<li>'
                    . Html::beginForm(['/site/logout'], 'post', ['class' => 'navbar-form'])
                    . Html::submitButton(
                        'Logout (' . Yii::$app->user->identity->username . ')',
                        ['class' => 'btn btn-link']
                    )
                    . Html::endForm()
                    . '</li>'
                )
    
    'user' => [
      'identityClass' => 'app\models\Admin',
      'enableAutoLogin' => true,
    ]