2017-06-20 71 views

回答

0

在index.php文件

  1. 初始化功能和路由URL

    $app->post('/xyz/routename', 'functionname'); 
    
  2. 创建功能

    function functionname() 
    { 
        $app = \Slim\Slim::getInstance(); 
        $credentials = $app->request->post(); 
    } 
    

在$证书中所有可用的输入字段值目的。

+0

Sujal Patel,我会检查它的先生。 – Raja

+0

Hi Sujal Patel,我必须初始化函数和路由URL(表单页面或细化页面)的哪个文件。 – Raja

+0

主要路线文件index.php –

0

你可以做这样的:

$this->app = new \Slim\Slim(); 

$this->app->post("/post/create", function() { 

    $userId = $this->app->request->post('user'); 

    // or 

    $allPostVars = $this->app->request->post(); 
    $userId = $allPostVars['user']; 
    //... 

}); 

,如果你不想使用匿名函数(“这是不可能的PHP 5.4.0前使用$这个匿名函数”),我认为你可以这样做:

$this->app->post("/post/create", 'createPost'); 


function createPost() { 
     $userId = $this->app->request->post('user'); 
     //... 
} 
0
$app->post('/api/v1/customers/new', function (Request $request, Response 
$response) { 
    $data = $request->getParsedBody(); 
    $ticket_data = []; 
    $ticket_data['name'] = filter_var($data['name'], FILTER_SANITIZE_STRING); 
    $ticket_data['age'] = filter_var($data['age'], FILTER_SANITIZE_STRING); 
    $response->getBody()->write(var_export($ticket_data, true)); 
    return $response; 
}); 

我只是想用下面它为我工作。

上述API的帖子主体有两个参数,即名称和年龄。返回响应以查看发送的值。

[please follow this tutorial for better understanding][1] 

    [1]: https://www.slimframework.com/docs/tutorial/first-app.html