2014-10-16 42 views
0
public function login() 
{ 
    if($this->request->is('post')){ 
     if($this->Auth->login()){ 
      var_dump('Logged in successfully'); 

     }else{ 
      var_dump('Log in failed'); 
     } 
    } 
} 

當我在寫上面的代碼中,我得到的輸出如下在瀏覽器中查看:CakePHP的驗證登錄REST響應

string(22) "Logged in successfully" 

但是當我重寫代碼如下使用爲REST API:

{ 
    message: "Error. Log in failed. Please, try again." 
} 
012:

public function login() 
{ 
    if($this->request->is('post')){ 
     if($this->Auth->login()){ 
      $message = 'Logged in successfully'; 

     }else{ 
      $message = 'Error. Log in failed. Please, try again.'; 
     } 
     $this->set(array(
      'message' => $message, 
      '_serialize' => array('message') 
     )); 
    } 
} 

像下面現在,我得到響應

我正在使用Chrome的「高級休息客戶端」擴展程序來檢查REST響應。

回答

0

我試圖登錄如下:

Wrong way to get the right response

但它工作得很好,給了我預期的響應當我如下進行:

Right way to get the right response