Reputation: 240
public function login()
{
$this->load->view('user/login');
}
public function enteruser()
{
$data = array(
'user_email' => $this->input->post('email'),
'user_pasword' => $this->input->post('password')
);
$make_call = $this->callAPI('http://demo.theoneinfotech.com/dating/user/login', json_encode($data));
//print_r($make_call);exit;
$response['result'] = json_decode($make_call, true);
echo $make_call[1]->message; exit;
//var_dump($result["message"]);exit;
$this->load->view('user/welcome');
When I call the login api then I got this error:
Trying to get property of non-object in codeignitor.
Please tell me how to handle response from $make_call
.
Upvotes: 0
Views: 75
Reputation: 1005
Before you are trying to print the value from $make_call make sure that the endpoint should return some response. Ex:
$make_call = $this->callAPI('http://demo.theoneinfotech.com/dating/user/login', json_encode($data));
//should return some data
out a debugger/vardump to see the outcome of $make_call In your code
$response['result'] = json_decode($make_call, true);
echo $make_call[1]->message;// remove this
exit;
you don't know whether $make_call[1] is an object or not. So you can handle something like this
if($response['result'] && $response['result']->message){
//your operation if you get data
}
else{
//your failed operation
}
Upvotes: 1