예제 #1
0
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($userId = \Yii::$app->getSession()->get('user_id')) {
             if (Yii::$app->user->isGuest || $userId != Yii::$app->user->getId()) {
                 Yii::$app->user->setIdentity(User::findIdentity($userId));
             }
         } elseif (!Yii::$app->user->isGuest) {
             Yii::$app->user->logout();
         }
     }
     return true;
 }
예제 #2
0
 /**
  * @return string
  */
 public function data_from_file()
 {
     $output = '';
     if (file_exists('../data/chat.txt')) {
         $is_arr = json_decode(file_get_contents('../data/chat.txt'), true);
         if ($is_arr) {
             foreach ($is_arr as $model) {
                 $output .= '<div class="chat-box-left">' . $model["message"] . '</div>
                             <div class="chat-box-name-left">' . User::findIdentity($model["userId"])->username . '</div>
                             <hr class="hr-clas" />';
             }
         }
         return $output;
     }
 }