简体   繁体   English

使用Slim Framework Php错误404的问题

[英]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. 我最近偶然发现了一段使用Sim Framework的代码,令人印象深刻,它不仅隐藏了文件,而且还简化了工作,与拥有多个文件不同,基本上可以调用一个方法,我不知道php是否可以做到这一点的默认值,但多数民众赞成在一个主要的原因我想使用它,试图使其工作小时后,还有至少它的工作,但post没有工作, get尽管没有工作,我不能说的事使用索引文件或其他任何方法,因为get方法与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. Slim框架具有出色的文档,所有发布方法均在文档中显示。

http://www.slimframework.com/docs/objects/router.html 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. 基本方法是发布完整的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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