[英]issues using Slim Framework Php error 404
我最近偶然發現了一段使用Sim Framework
的代碼,令人印象深刻,它不僅隱藏了文件,而且還簡化了工作,與擁有多個文件不同,基本上可以調用一個方法,我不知道php是否可以做到這一點的默認值,但多數民眾贊成在一個主要的原因我想使用它,試圖使其工作小時后,還有至少它的工作,但post
沒有工作, get
盡管沒有工作,我不能說的事使用索引文件或其他任何方法,因為get
方法與get
在同一個文件中。
這是要求的完整代碼:
<?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框架具有出色的文檔,所有發布方法均在文檔中顯示。
http://www.slimframework.com/docs/objects/router.html
$app = new \Slim\App();
$app->post('/books', function ($request, $response, $args) {
// Create new book
});
那正在工作。 要獲得更多幫助,您必須發布代碼和更多信息。 基本方法是發布完整的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.