2015-10-19 58 views
0

代碼:奇怪的行爲,笨數據庫

array(29) { 
    ["id"]=> string(1) "1" 
    ["id_user_groups"]=> string(1) "3" 
    ["email"]=> string(16) "[email protected]" 
    ["username"]=> string(7) "Demouser" 
    ["password"]=> string(60) "$2y$10$fi0zUzFlMm9QJEV5ZVo9eQMQMYApytT1asiePbSB9y" 
    ["ip_address"]=> string(9) "127.0.0.1" 
    ... 
    ... 
} NULL 

正如你可以看到函數foo()的工作,因爲它應該是,在:的var_dump()的

function foo ($param) 
{ 
    $this->ci->db->select ( '*' ); 
    $this->ci->db->from ($this->tableUser [ 'table' ] . ' as u'); 
    $this->ci->db->where ('u.' . $this->tableUser [ 'column' ] [ 'id' ], $param); 
    $query = $this->ci->db->get (); 
    if (! $query) { throw new Exception ('Something went wrong') } 
    $data = $query->unbuffered_row ('array'); 
    var_dump($data); 

    $data [ $this->tableUser [ 'username' ] ] 
} 

結果var_dump()結果也不錯,$ data是一個關聯數組,但仍然在行$data [ $this->tableUser [ 'username' ] ]我收到以下錯誤。 爲什麼?

甲PHP錯誤遇到

嚴重性:注意

消息:未定義指數:用戶名

文件名:用戶/ user.php的

行號:439

+1

想要澄清一下,首先訪問像這樣的'$ data ['username']'和'echo $ this-> tableUser;'看看你在兩者中都得到了什麼。 –

+0

@NiranjanNRaju oops:P謝謝。 – StudentX

+0

其工作正常?錯誤是什麼? –

回答

1

replace t他行,

$data [$this->tableUser['username']] 

$data ['username']; 

如果你想使用$this->tableUser,第一echo $this->tableUser;和檢查什麼是在未來。