第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Codeigniter 3 應(yīng)用程序錯誤:無法在會話中存儲某些列值

Codeigniter 3 應(yīng)用程序錯誤:無法在會話中存儲某些列值

PHP
藍山帝景 2023-12-15 15:04:52
我正在使用 Codeigniter 3 開發(fā)社交網(wǎng)絡(luò)應(yīng)用程序,Ion-Auth。Github 存儲庫 和 Bootstrap 4。您可以在此處查看我想將登錄用戶的 first_name 存儲到當(dāng)前會話中。為此,我在原始 $session_data 數(shù)組中添加了行 'user_first_name' => $user->first_name,$session_data = [        'identity'                 => $user->{$this->identity_column},         $this->identity_column     => $user->{$this->identity_column},        'email'                    => $user->email,        'user_id'                  => $user->id,        'user_first_name'          => $user->first_name, //retrieve from the first_name column        'old_last_login'           => $user->last_login,        'last_check'               => time(),        'ion_auth_session_hash'    => $this->config->item('session_hash', 'ion_auth'),];重點是在用戶 ID 登錄后顯示歡迎消息:Welcome, <?php echo $this->session->userdata('user_first_name'); ?>我收到 Undefined property $first_name 消息,歡迎消息僅包含“歡迎,” (盡管事實上$this->session->userdata('user_first_name') 確實返回用戶的ID)。缺什么?
查看完整描述

1 回答

?
MM們

TA貢獻1886條經(jīng)驗 獲得超2個贊

快速檢查$user中的內(nèi)容Ion_auth_model.php、set_session() 正在使用 var_dump 顯示它是...


LINE: 1944 Module Ion_auth_model

object(stdClass)#26 (5) {

  ["email"]=>

  string(21) "frednurk@gmail.com"

  ["id"]=>

  string(1) "8"

  ["password"]=>

  string(60) "$2y$10$MGlESdMfrr/UNd.mdW4Vr.nyTqES0SB6rEnaDBOYocwU7yLXVqNMq"

  ["active"]=>

  string(1) "1"

  ["last_login"]=>

  string(10) "1599322333"

}

不包含first_name。由于錯誤消息,這正是您所期望的。


搜索調(diào)用此函數(shù)的位置,將帶您返回 Ion_auth_model.php - 登錄,其中 $user 的選擇查詢是


$query = $this->db->select($this->identity_column . ', email, id, password, active, last_login')

                  ->where($this->identity_column, $identity)

                  ->limit(1)

                  ->order_by('id', 'desc')

                  ->get($this->tables['users']);

正如預(yù)期的那樣,它丟失了first_name。


因此,將first_name 添加到選擇中,如下所示...


$query = $this->db->select($this->identity_column . ', email, id, password, active, last_login, first_name')

                  ->where($this->identity_column, $identity)

                  ->limit(1)

                  ->order_by('id', 'desc')

                  ->get($this->tables['users']);

結(jié)果 $user 變成...


LINE: 1944 Module Ion_auth_model

object(stdClass)#26 (6) {

  ["email"]=>

  string(21) "frednurk@gmail.com"

  ["id"]=>

  string(1) "8"

  ["password"]=>

  string(60) "$2y$10$MGlESdMfrr/UNd.mdW4Vr.nyTqES0SB6rEnaDBOYocwU7yLXVqNMq"

  ["active"]=>

  string(1) "1"

  ["last_login"]=>

  string(10) "1599322333"

  ["first_name"]=>

  string(3) "Tim"

}

然后就一切皆大歡喜了。

結(jié)論

  1. 閱讀錯誤消息

  2. 通過檢查變量/數(shù)組/對象來查看它們是什么來執(zhí)行調(diào)試。

  3. 回來修復(fù)它。

調(diào)試時,我使用了這個小代碼片段

echo '<pre>';

echo 'LINE: '. __LINE__. ' Module '.__CLASS__.'<br>';

var_dump(WHAT_TO_LOOK_AT_GOES_HERE);

echo '</pre>';


查看完整回答
反對 回復(fù) 2023-12-15
  • 1 回答
  • 0 關(guān)注
  • 175 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號