slim

How to access a JSON request body of a POST request in Slim?

狂风中的少年 提交于 2019-12-18 19:08:09
问题 I'm just a newbie in the Slim framework. I've written one API using Slim framework. A POST request is coming to this API from an iPhone app. This POST request is in JSON format. But I'm not able to access the POST parameters that are sent in a request from iPhone. When I tried to print the POST parameters' values I got "null" for every parameter. $allPostVars = $application->request->post(); //Always I get null Then I tried to get the body of a coming request, convert the body into JSON

Multiple routes with the same anonymous callback using Slim Framework

谁都会走 提交于 2019-12-18 05:47:06
问题 How can I define multiple routes that use the same anonymous callback? $app->get('/first_route',function() { //Do stuff }); $app->get('/second_route',function() { //Do same stuff }); I know I can use a reference to a function which would work, but I'd prefer a solution for using the anonymous function to be consistent with the rest of the codebase. So basically, what I'm looking for is a way of doing something like this: $app->get(['/first_route','/second_route'],function() { //Do same stuff

How to retrieve POST data from PhoneGaps File Transfer API

我的梦境 提交于 2019-12-17 19:14:56
问题 I'm using Phone Gaps (Cordova 2.1) file transfer API to post an image from the users photo library to my server. The file transfer API seems to be working fine. I'm just puzzled about retrieving this information on my server. Ideally, what I need to do is retrieve the image then upload it to my server. However, I can't seem to retrieve any information from the file transfer? My JavaScript code (posting image data) is: function onDeviceReady() { // Retrieve image file location from specified

Slim framework and GET/PUT/POST methods

99封情书 提交于 2019-12-17 17:10:34
问题 For example, i use this code for testing routes: $app->get('/api', function () { echo 'get!'; }); $app->post('/api', function () { echo 'post!'; }); $app->put('/api', function () { echo 'put!'; }); For api testing i use RestClient plugin for Chrome. When i try do GET request, response is 'get!'. Its good. But: When i try do POST request, response also is 'get!'. Why? Its must be 'post!'. When i try do PUT request, (in Response Headers: Allow: GET,HEAD,POST,OPTIONS,TRACE ) Slim response have

在PHP中检测请求类型(GET,POST,PUT或DELETE)

痴心易碎 提交于 2019-12-16 19:41:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 如何检测PHP中使用了哪种请求类型(GET,POST,PUT或DELETE)? #1楼 由于这与REST有关,因此仅从服务器获取请求方法是不够的。 您还需要接收RESTful路由参数。 分离RESTful参数和GET / POST / PUT参数的原因是,资源需要具有自己的唯一URL进行标识。 这是使用Slim在PHP中实现RESTful路由的一种方法: https://github.com/codeguy/Slim $app = new \Slim\Slim(); $app->get('/hello/:name', function ($name) { echo "Hello, $name"; }); $app->run(); 并相应地配置服务器。 这是使用AltoRouter的另一个示例: https://github.com/dannyvankooten/AltoRouter $router = new AltoRouter(); $router->setBasePath('/AltoRouter'); // (optional) the subdir AltoRouter lives in // mapping routes $router->map('GET|POST','/', 'home

Download file from Slim Framework 2.4

我与影子孤独终老i 提交于 2019-12-14 03:44:36
问题 I am trying to let the user download a file in the Slim php framework. The intended use is that the file will be: http://api.test.com/item/123.json <- returns json string with data http://api.test.com/item/123.pdf <- download pdf-file with human-readable presentation of data I have the code producing the PDF, but what I need is to make Slim send the correct headers so the file will be downloaded. This is the following code I have (working) for the existing system: header("Pragma: public");

AJAX - 404 with Slim PHP

ⅰ亾dé卋堺 提交于 2019-12-13 12:44:07
问题 I'm getting a 404 (Not found) in the console when trying to get data with AJAX in my Slim PHP application. Here's the error message : http://localhost:8888/Project/mods/public/edit-mod/ajax/get-categories?gameID=1 404 (Not Found) Here's the route defined in a routes.php file (that is correctly included, all the other routes are working) : $app->get("/ajax/get-categories/", function() use ($app, $User, $Game, $Mod){ //Fetch data and echo it }); Finally, here's how I'm calling the AJAX page in

Some method is not resolvable

╄→尐↘猪︶ㄣ 提交于 2019-12-13 09:05:18
问题 Work on API project. Everything good until I have to add a new endpoint (new method too) and I got this Error for my new endpoint, another endpoint run well. Below is error log: Type: RuntimeException Message: [{“container”:{}},“getNotification”] is not resolvable File: /opt/myanime/api/vendor/slim/slim/Slim/CallableResolver.php Line: 104 Trace #0 /opt/myanime/api/vendor/slim/slim/Slim/CallableResolver.php(62): Slim\CallableResolver->assertCallable(Array) #1 /opt/myanime/api/vendor/slim/slim

Working with Slim Framework and htaccess

▼魔方 西西 提交于 2019-12-13 07:40:08
问题 I have the following code: RewriteEngine On # If you need to use the `RewriteBase` directive, it should be the # absolute physical path to the directory that contains this htaccess file. # # RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^category/(.*)$ searchPage.php?crs_category=$1 [NC,QSA] RewriteRule ^ index.php [QSA,L] Now the way Slim Framework works is that all requests are redirected to index.php , where index.php route the requested

Slim Routing - Routes ignored

狂风中的少年 提交于 2019-12-13 04:29:54
问题 I've a problem how to model my routes so they get recognized correctly. I've the following routes: $app->get('/courses/:id', function ($id) use ($app) { $app->render(200, array("Id parameter")); }); $app->get('/courses/attendees', function () use ($app) { $app->render(200, array("attendee Parameter")); }); $app->get('/courses/search', function () use ($app) { $app->render(200, array("search Parameter")); }); If I call the URI localhost/courses/12 I'll get the expected result "Id parameter"