2016-04-03 106 views
0

我有一個php函數。僅返回的函數FALSE

   if ($this->input->post('email') == $this->_email($this->input->post('email'))) 
      { 
       $this->_data['error'] = 'Email exist!'; 
       return $this->load->view('login/template_view', $this->_data); 
      } 

我的函數只返回FALSE,即使等於true。我使用調試來查看我的函數是否可以返回TRUE。

bool(false) string(14) "[email protected]" object(stdClass)#25 (1) { ["email"]=> string(14) "[email protected]" } 

我有2個串,首先是返回[email protected],和第2串返回[email protected] ......但如果這種情況仍返回FALSE。

我的功能有什麼問題?

調試:

   var_dump($this->input->post('email')); 
       var_dump($this->_email($this->input->post('email'))); 
       die(); 
+0

'$這個 - >電子郵件()'返回'stdClass',而不是一個'string' ..這根本不會一樣。你的對象包含一個'email'成員,這是你應該比較你的第一個字符串。 – Brice

+0

哦,你說得對。但我怎麼可以從對象中提取電子郵件[字符串]?我開始與codeigniter。如果你能解釋我,我真的很贊同 – RedoColor

+0

此外,只是'$ this-> load-> view('login/template_view',$ this - > _ data);''不帶'return'。 – Tpojka

回答

0

你是一個字符串比較的對象。爲了使您的比較起作用,您需要將該字符串與對象的email屬性進行比較。您可以通過使用->或使用方法來訪問對象屬性。

您可以閱讀更多關於PHP對象herehere的信息。

爲了使您的代碼工作,更換:

if ($this->input->post('email') == $this->_email($this->input->post('email'))) 

if ($this->input->post('email') == $this->_email($this->input->post('email'))->email) 
+0

謝謝你的幫助! – RedoColor