在我的第一个苗条项目中工作,所以我怀疑我缺少一些简单的东西。
这是在WAMP开发环境中。
我有一个名为getValue.php的文件,该文件具有简单的形式,并将值传递给名为index.php的超薄API文件。
index.php方面的所有处理均正常工作,但slim似乎只是在http://localhost/project/index.php/value中显示json响应,而不是将其传递回getValue.php。我希望getValue.php处理响应显示。
这是getValue.php
<?php
if (!empty($_POST['uid'])) {
$json = 'index.php/value?uid=' . $_POST['uid'];
$arr = file_get_contents($json);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>value</title>
</head>
<body>
<form action="index.php/value" method="post">
<input type="text" name="uid"/>
<button type="submit">Submit</button>
</form>
<br/>
<?php
if(!empty($arr)){
echo json_decode($arr, true);
}
?>
</body>
</html>
这是index.php
<?php
use \Slim\Slim;
$app = new Slim(array(
'mode' => 'development'
));
$app->post('/value', function () use ($app){
$uid = $app->request->params('uid');
$uid = $uid + 1;
$arr = array("uid" => $uid);
$response = $app->response();
$response['Content-Type'] = 'application/json';
$response->body(json_encode($arr));
});
邮递员似乎可以发送,接收和显示响应。
有任何想法吗?
正如您所想象的,这很简单:表单中的操作是错误的。由于您希望该getValue.php
脚本处理POST,因此应将其用作表单操作。这条路:
<form action="getValue.php" method="post">
您现在的操作方式是绕过getValue.php
脚本将表单直接发布到Slim路由中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句