你猜怎么着,我刚遇到这个问题,刚刚解决了这个问题。我不得不回溯所有对象然后得到东西。将该字段添加到 register.ph 和 newuser 类后,
- 转到 models/funcs.php ,找到函数 fetchUserDetails (第 ~ 318 行)。在 $stmt 变量中添加您的字段(第 345 行)。
- 再次将其添加到行 (~354, ~456)。
- 转到 login.php,转到行 (~ 60 ) 并设置在其他变量的末尾添加您的变量(在注释下 - 将一些 db 数据传输到会话对象)
而已。使用此代码检查您是否获得了所需的字段:
<pre>
<?php print_r(get_object_vars($loggedInUser)); ?>
</pre>
例如,我想添加 dob (date Of Birth ) 字段,在添加要注册的值、新用户类和 func.php 文件、登录文件后,我的文件如下所示:
登录.php
//Construct a new logged in user object
//Transfer some db data to the session object
$loggedInUser = new loggedInUser();
$loggedInUser->email = $userdetails["email"];
$loggedInUser->user_id = $userdetails["id"];
$loggedInUser->hash_pw = $userdetails["password"];
$loggedInUser->title = $userdetails["title"];
$loggedInUser->displayname = $userdetails["display_name"];
$loggedInUser->username = $userdetails["user_name"];
$loggedInUser->dob = $userdetails["dob"];
函数.php
//Retrieve complete user information by username, token or ID
function fetchUserDetails($username=NULL,$token=NULL, $id=NULL)
{
if($username!=NULL) {
$column = "user_name";
$data = $username;
}
elseif($token!=NULL) {
$column = "activation_token";
$data = $token;
}
elseif($id!=NULL) {
$column = "id";
$data = $id;
}
global $mysqli,$db_table_prefix;
$stmt = $mysqli->prepare("SELECT
id,
user_name,
display_name,
password,
email,
activation_token,
last_activation_request,
lost_password_request,
active,
title,
sign_up_stamp,
last_sign_in_stamp,
dob
FROM ".$db_table_prefix."users
WHERE
$column = ?
LIMIT 1");
$stmt->bind_param("s", $data);
$stmt->execute();
$stmt->bind_result($id, $user, $display, $password, $email, $token, $activationRequest, $passwordRequest, $active, $title, $signUp, $signIn,$dob);
while ($stmt->fetch()){
$row = array('id' => $id, 'user_name' => $user, 'display_name' => $display, 'password' => $password, 'email' => $email, 'activation_token' => $token, 'last_activation_request' => $activationRequest, 'lost_password_request' => $passwordRequest, 'active' => $active, 'title' => $title, 'sign_up_stamp' => $signUp, 'last_sign_in_stamp' => $signIn,'dob'=>$dob);
}
$stmt->close();
return ($row);
}
希望这可以帮助。