1、将common/models/User.php在当前目录下copy一份,命名为Admin.php,修改类的名称为Admin
2、将common/models/LoginForm.php复制到backend/models/LoginForm.php
修改backend/models/LoginForm.php
namespace backend\models; use common\models\Admin;......
protected function getUser()
{
if ($this->_user === null) {
$this->_user = Admin::findByUsername($this->username);
}
return $this->_user;
}
3、将common/models/LoginForm.php复制到frontend/models/LoginForm.php
修改frontend/models/LoginForm.php
namespace frontend\models; use common\models\User;
4、删除common/models/LoginForm.php
5、修改backend/config/main.php
'components' => [ 'user' => [ 'identityClass' => 'common\models\Admin', 'enableAutoLogin' => true, ], ... ]
6、修改frontend/config/main.php
'components' => [ 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, ], ... ]
7、修改控制器backend/controllers/SiteController.php
namespace backend\controllers; use Yii; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use backend\models\LoginForm;