Update this code in the index but I am unable to access this result method.
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');});
$app->post('/result', function () use ($app) {
$roll_no = $app->request->post('roll_no');
$db = new DbOperation();
$response = array();
if ($db->result($roll_no)) {
$student = $db->getStudentR($roll_no);
$response['error'] = false;
$response['student_name'] = $student['student_name'];
} else{
$response['error'] = true;
$response['message'] = "Invalid username or password";
}
echoResponse(200, $response);});
Thank you. how can be accessed slim method?
you do not run your method. Also, you have to reteurn a response object:
$app->post('/result', function (RequestInterface $request, ResponseInterface $response) use ($app) {
$roll_no = $app->request->post('roll_no');
$db = new DbOperation();
$result= array();
if ($db->result($roll_no)) {
$student = $db->getStudentR($roll_no);
$result['error'] = false;
$result['student_name'] = $student['student_name'];
} else{
$result['error'] = true;
$result['message'] = "Invalid username or password";
}
$response->getBody()->write(json_encode($result));
return $response;});
$app->run();
you should then be able to run as follows:
your-domain.com/result