0

当用户登录时,他的联系人会显示在索引页面上。在这种情况下,用户 ID 是 17,但是当我使用 var_dump 检查它时,它只获取“1”而不是“17”。因此,不显示任何数据。

索引.php

function home()
{
    $results = array();
    $results['pagetitle'] = "Home";

    $homeobj = new data( $_SESSION['user_id'] );
    $results['contacts'] = $homeobj->getcontacts();
    require 'templates/home_form.php';
}

数据类.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']);

    } 
4

1 回答 1

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
于 2013-09-18T09:58:44.237 回答