简体   繁体   中英

issues using Slim Framework Php error 404

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();
?>

Slim framework has a great documentation and all post methods are shown in the documentation.

http://www.slimframework.com/docs/objects/router.html

$app = new \Slim\App();
$app->post('/books', function ($request, $response, $args) {
    // Create new book
});

that is working. For more help you have to post your code and more informations. Bist way is to post your complete code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM