- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天我开始学习 slim php 以便我可以开始发布和保存数据到 mysql。我现在遇到的问题是我尝试将下面的示例代码与此 url http://localhost/MyRest/index.php/updateScore?id=1&score=36
一起使用但无法发送参数。如果可能的话,你能给我一份 sample 或小费吗?我很想听听你的意见!
$app->post('/updateScore', function() use($app){
$allPostVars = $app->request->post();
$score = $allPostVars['score'];
$id = $allPostVars['id'];
try
{
$db = getDB();
$sth = $db->prepare("UPDATE students
SET score = :score
WHERE student_id = :id");
$sth->bindParam(':score', $score, PDO::PARAM_INT);
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->execute();
$app->response->setStatus(200);
$app->response()->headers->set('Content-Type', 'application/json');
echo json_encode(array("status" => "success", "code" => 1));
$db = null;
} catch(PDOException $e) {
$app->response()->setStatus(404);
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
});
最佳答案
来自网址:http://localhost/MyRest/index.php/updateScore?id=1&score=36
您正在将参数作为查询字符串发送。因此它不会进入 post
方法。你需要 get
方法。
请更改为:
$allPostVars = $app->request->post();
为此:
$allPostVars = $app->request->get();
关于php - 无法在 Slim PHP 中发布参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35437238/
.net 4.0 添加了几个与线程相关的新类:ManualResetEventSlim , SemaphoreSlim和 ReaderWriterLockSlim . Slim 版本和旧类之间有什么区
一个新的 Slim 问题 我期待以下 Slim 模板 div class="header" h2 slim head p a test example of span Slim span a
我们正在考虑使用 Slim 3 作为我们 API 的框架。我已经搜索过 SO 和 Slim 文档,但找不到问题的答案。如果我们有不同的路由文件(例如 v1、v2 等)并且如果两个路由具有相同的签名,则
我正在尝试在 Slim-lang 的列表项中嵌套第二个 ul,如下所示: div.row ul.dropdown li Dropdown Option 1
我有以下代码导致 Slim::Parser::SyntaxError : p code.inline /charge 我希望这会输出 /charge但这只会让斯林姆不高兴。 为什么? 最佳答案 使
我想在子目录中使用 Slim 3,但似乎无法加载它。所有文件都包含在子目录中,包括 composer.json。这是我的 composer.json: "require": { "slim/s
我的 Slim 项目组织如下: - app -- Acme --- Auth ---- Auth.php (handles authentication) -- config --- developm
我在我的 svelte-typescript 项目上使用 clickOutside 指令,当我将自定义事件分配给相关元素时出现此错误 Type '{ class: string; onclick_ou
我们缩小了在 Silex 和 Slim PHP 框架之间的搜索范围,以便在我们的 Apache/PHP/MySQL 服务器上路由我们的 REST API。 两者似乎都有很好的评价。 Silex 可能有
我有一个 get表格中的路线 $app->get('/redirect[/{subject}]', function ($request, $response, $args) { }); 如果我向 /
任何人都可以解释在选择使用钩子(Hook)而不是使用中间件来实现身份验证或缓存等功能时是否有任何显着的优点或缺点? 例如 - 我可以通过自定义中间件获取请求对象并设置应用程序语言变量来实现翻译功能,该
在 Slim 3 中是否有类似 Laravel 的 back() helper 来获取之前的路由名称或 uri? 它不必特定于 Slim,我只是想重定向回上一页。 谢谢:) 最佳答案 假设你想要 re
在 Slim 3 中是否有类似 Laravel 的 back() helper 来获取之前的路由名称或 uri? 它不必特定于 Slim,我只是想重定向回上一页。 谢谢:) 最佳答案 假设你想要 re
我正在学习这里的教程: https://www.simplifiedcoding.net/php-restful-api-framework-slim-tutorial-1/ 导师说下载slim在:
如何从不同的 php 页面中的另一个函数调用 slim 函数 这里是 My.php: $app->get('/list/:id',function($id) { //fill array her
很抱歉提出这样一个愚蠢的问题,但在文档中找不到它: filename.slim filename.html.slim 这似乎是一种非常适合使用的语言。我以前使用过 HAML,所以我认为这将是一个相当不
请原谅我的无知,但我只是使用 npm 安装了 jQuery,并且在 jQuery 文件之间有一个名为 jquery.slim.js 的文件,slim 是什么?我知道 min 代表缩小但 slim 对我
TailwindCSS 看起来像是一个很棒的前端工具,但我想知道如何将它与 Rails Slim 模板语言一起使用? 例如: 如果我通过 HTML2SLIM 运行它,我会得到这个建议: .bg-re
TailwindCSS 看起来像是一个很棒的前端工具,但我想知道如何将它与 Rails Slim 模板语言一起使用? 例如: 如果我通过 HTML2SLIM 运行它,我会得到这个建议: .bg-re
我想将纤薄的 textmate 包安装到 sublime2。 我去了这个链接 slim textmate bundle 我将它克隆到 pristinepackage(根据 nettuts 网站),但什
我是一名优秀的程序员,十分优秀!