I recently stumbled on a piece of code that was using Sim Framework
and it was impressive, not only did it hide the files but it also simplified work, unlike having multiple files, one could basically call a method, I do not know if php can do that by default but thats one of the main reason I want to use it, after hours of trying to make it work, well at least it worked but post
has not worked, get
did work though, I can't say its something to do with the index file or anything because the get
method is in the same file as the get.
Here is requested complete code:
<?php
require_once '../include/DbOperation.php';
require '.././libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
/**
* Method is working
*/
$app->get('/testing', function () {
echo 'testing Slim Framework'
});
/**
* Method is not working outputing Error 404
*/
$app->post('/createstudent', function () use ($app) {
verifyRequiredParams(array('name', 'username', 'password'));
$response = array();
$name = $app->request->post('name');
$username = $app->request->post('username');
$password = $app->request->post('password');
$db = new DbOperation();
$res = $db->createStudent($name, $username, $password);
if ($res == 0) {
$response["error"] = false;
$response["message"] = "You are successfully registered";
echoResponse(201, $response);
} else if ($res == 1) {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registereing";
echoResponse(200, $response);
} else if ($res == 2) {
$response["error"] = true;
$response["message"] = "Sorry, this student already existed";
echoResponse(200, $response);
}
});
$app->run();
?>