当用户登录时,他的联系人会显示在索引页面上。在这种情况下,用户ID是17但是当我使用var_dump检查它时,它只是获取'1'而不是'17'。因此,不会显示任何数据。
的index.php
function home()
{
$results = array();
$results['pagetitle'] = "Home";
$homeobj = new data( $_SESSION['user_id'] );
$results['contacts'] = $homeobj->getcontacts();
require 'templates/home_form.php';
}
data.class.php
public function __construct( $data = array() )
{
if( isset($data['user_id'])) (int)$this->user_id = $data['user_id'];
var_dump( $data['user_id'] ); // 1
var_dump( $data); // 17
if( isset($data['username']) ) $this->username = $data['username'];
if( isset($data['password']) ) $this->password = sha1($data['password']);
if( isset($data['repass']) ) $this->repass = sha1($data['repass']);
}
答案 0 :(得分:1)
您没有在构造函数中传递数组
$homeobj = new data( $_SESSION['user_id'] ); //here $_SESSION['user_id'] is just an integer id
尝试改为
$data['user_id'] = $_SESSION['user_id'];
$homeobj = new data( $data ); //pass array