Yii2.0多次登录

I am creating a site in yii2.0.4. There is two login section one for normal user and other for business user and both have different tables. I have created login for both and it is working fine but when I click on logout it does not work. other problem is suppose there is an Id for logged in user is 1 and same id belongs from other table for business user than Yii takes both identity and it show two logout button one for business user and other for normal user but it should show only one logout and Yii should keep identity for that particular controller/login. Please help what can i do.

This is my controller {

use Yii;
use yii\helpers\FileHelper;
use yii\filters\AccessControl;
use yii\web\Controller;
use frontend\models\BusinessLoginForm;
use frontend\models\NewBusinessForm;
use yii\filters\VerbFilter;
use frontend\models\Business;
use common\models\UploadForm;
use yii\web\UploadedFile;
use common\models\UploadImage;
use common\models\BusinessCat;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use frontend\models\MessagesForm;
use common\models\Messages;




/**
 * Business controller
 */
class BusinessController extends Controller
{
    /**
     * @inheritdoc
     */
   public function behaviors()
    {
       return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup','confirm'],
                'rules' => [
                    [
                        'actions' => ['signup','confirm'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

     public function actions()
    {

        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }


     /**
     * Creates a new Business model.
     * If creation is successful, the browser will be redirected to the 'create' page.
     * @return mixed
     */

    public function actionCreate()
    {
             if (!\Yii::$app->users->isGuest || !\Yii::$app->business->isGuest) {
                    return $this->goHome();
                }
            $mimeMagicFile = 'yii/helpers/mimeTypes.php';
            $model = new NewBusinessForm();

            $modleimage = new UploadForm();
            $modleimage->path = Yii::$app->basePath.'/../uploads/businessImages/';

            $modleimage->imageID = UploadedFile::getInstances($model, 'imageID');
            $modleimage->businessID = time();

           if ($model->load(Yii::$app->request->post()) && $model->validate()) {

               if(count($modleimage->imageID)>0){

                   if($modleimage->multipleUpload()){

                          if($business = $model->newBusiness()){
                              $newid = Yii::$app->db->getLastInsertID();

                              foreach($model->catID as $catIDs){

                                   Yii::$app->db->createCommand()
                                    ->insert('businesscat', ['businessID' => $newid,'catID'=>$catIDs])
                                    ->execute();
                             }


                                foreach ($modleimage->imageID as $file) {

                                    $uploadfilename = $modleimage->businessID ."_".$file;
                                    Yii::$app->db->createCommand()
                                    ->insert('businessimage', ['imageID' => $uploadfilename,'businessID'=>$newid])
                                    ->execute();

                                }
                                Yii::$app->getSession()->setFlash('success', 'Your business account has been created successfully. Confirmation link has been sent your email please click on that link and verify your account.');
                                return $this->redirect(['create']); 
                          }else{
                              Yii::$app->getSession()->setFlash('error', 'Error to save data.');
                          }

                         }else{
                                    $totalimages = count($modleimage->imageID);
                                   if($totalimages>4){
                                       Yii::$app->getSession()->setFlash('error', 'You can not upload more than 4 images.');
                                   }else{
                                       Yii::$app->getSession()->setFlash('error', 'You can nt upload image more than 2 MB.');
                                   } 
                         }

                     }else{

                         if($business = $model->newBusiness()){
                              $newid = Yii::$app->db->getLastInsertID();
                             foreach($model->catID as $catIDs){

                                   Yii::$app->db->createCommand()
                                    ->insert('businesscat', ['businessID' => $newid,'catID'=>$catIDs])
                                    ->execute();
                             }

                Yii::$app->getSession()->setFlash('success', 'Your business account has been created successfully. Confirmation link has been sent your email please click on the link and verify your account.');
                                return $this->redirect(['create']); 
            }else{
                Yii::$app->getSession()->setFlash('error', 'Error to save data.');
            }

                     }
                     return $this->refresh();

           } 

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


    }

        public function actionConfirm($vcode)
        {
            $model = $this->findNewBusiness($vcode,'login');
         if($model){
            Yii::$app->db->createCommand()
          ->update('business', ['mtype' => 1,'vcode' => ''], 'vcode= "'.$vcode.'"')
          ->execute();
            return $this->render('confirm');
         }

      }

    public function actionAccount()
    {
            if (Yii::$app->business->isGuest) {
                    return $this->redirect(['login']);
                }
        return $this->render('account');
    }

        public function actionMessage($id = NUll)
        {
            if (Yii::$app->business->isGuest) {
                    return $this->redirect(['login']);
                }
            $busid = Yii::$app->business->identity->businessID;

         $inbox = Messages::find()->where(['receiverID'=>$busid])->groupBy('senderID')->orderBy(['created'=>SORT_DESC])->all();



            $msgid = $id;
            $model = new MessagesForm();

            $model->utype = 1;
            $model->sndrID = Yii::$app->business->identity->businessID;
            $model->recvID = empty($id)?$inbox[0]['senderID']:$id;

            if ($model->load(Yii::$app->request->post())) {
                 if($messages = $model->saveNewMessage()){
                      return $this->refresh();
                 }else{
                     Yii::$app->getSession()->setFlash('error', 'Error to save data.');
                 }
            }

                return $this->render('message',[
                    'model' => $model,
                    'latid' => $msgid,
                ]);

        }

        public function actionLogin()
            {
                if (!\Yii::$app->business->isGuest || !\Yii::$app->users->isGuest) {
                    return $this->goHome();
                }
                $model = new BusinessLoginForm();
                if ($model->load(Yii::$app->request->post()) && $model->login()) {
                    return $this->redirect(Yii::$app->request->referrer);
                } else {
                    return $this->render('login', [
                        'model' => $model,
                    ]);
                }
            }

    public function actionLogout()
    {
        Yii::$app->business->logout();
        return $this->goHome();
    }

    protected function findNewBusiness($id,$page)
    {
       if (($model = Business::findOne(['mtype' => '0', 'vcode' => $id])) !== null) {
            return $model;
        } else {
            return $this->redirect([$page]); 
        }
    }

}

}

This is my frontend/models

<?php

namespace frontend\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use common\models\Category;
use common\models\BusinessCat;

/**
 * This is the model class for table "business".
 *
 * @property integer $businessID
 * @property string $Email
 * @property string $Password
 * @property string $Overview
 * @property string $qsignin
 * @property string $Bname
 * @property string $Address
 * @property string $website
 * @property string $Cnumber
 * @property integer $mtype
 * @property integer $busCat
 * @property integer $searchA
 * @property string $created
 */
class Business extends \yii\db\ActiveRecord
{
public $imageID;
public $catID;

/**
 * @inheritdoc
 */
public static function tableName()
{
    return 'business';
}

/**
 * @inheritdoc
 */

public function rules()
{
    return [
       [['Email', 'Password', 'Overview', 'qsignin', 'Bname', 'Address', 'website', 'Cnumber', 'searchA','catID'], 'required'],
        ['Email', 'unique', 'targetClass' => '\common\models\Business', 'message' => 'This email address has already been taken.'],
        [['website'], 'string'],
        [['searchA'], 'string'],
        [['Email'], 'string', 'max' => 55],
        [['Password'], 'string', 'max' => 155],
        [['Overview'], 'string', 'max' => 500],
        [['qsignin'], 'string', 'max' => 10],
        [['Bname'], 'string', 'max' => 255],
        [['Address'], 'string', 'max' => 300],
        [['Cnumber'], 'string', 'max' => 15],
    ];
}

/**
 * @inheritdoc
 */

public function attributeLabels()
{
    return [
        'businessID' => 'Business ID',
        'Email' => 'Email',
        'Password' => 'Password',
        'Overview' => 'Overview',
        'qsignin' => 'Qsignin',
        'Bname' => 'Business Name',
        'Address' => 'Address',
        'website' => 'Website',
        'Cnumber' => 'Contact number',
        'mtype' => 'Member type',
        'catID' => 'Business Category',
        'searchA' => 'Search Area',
    ];
}

public function getBusinesscats()
{
    return $this->hasMany(Businesscat::className(), ['businessID' => 'businessID']);
}

/**
 * @return \yii\db\ActiveQuery
 */
public function getBusinessimages()
{
    return $this->hasMany(Businessimage::className(), ['businessID' => 'businessID']);
}
}

and the I have created yii/web/Business.php and BusinessEvent.php using yii/web/User.php or UserEvent.php only I have changed the class name. and my common/models file for getidentity as same as common/models/User.php only I have changed class name.

douchao0358
douchao0358 是否有人可以提出我的问题答案并解决我的问题
大约 5 年之前 回复
douzhanglu4591
douzhanglu4591 我现在已经给出了代码请帮助,这是非常紧急的。如果您需要更多细节,我将为您提供。
大约 5 年之前 回复
dongtan5555
dongtan5555 没有示例代码,这个问题很难回答
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问