簡體   English   中英

超薄框架php GET和POST

[英]Slim framework php GET and POST

我試圖弄清楚靜態的api在php中如何工作。 代碼如何獲取例如從javascript瀏覽器插件(我正在從事的工作)中傳遞的信息。 是通過GET還是POST? 有人可以提供例子嗎?

只需查看Slims主頁上的示例:

$app->get('/hello/:name', function ($name) {
    echo "Hello, $name";
});

如果您正在執行POST:

$app->post('/hello/:name', function ($name) {
    echo "Hello, $name";
});

您未映射到URL的任何參數在$_GET$_POST中仍然可用(例如/hello/kitty/?kat=42 )。

    <?php
    require 'vendor/autoload.php';//attaching the file.
    $app = new\Slim\Slim();//creating a instance of slim.

    /*get routes without parameter*/
    $app->get('/', function () {  
        echo "<center><b>Welcome To SLIM FrameWork-2</b></center><br>";
    });

    /*get routes with parameter*/
    $app->get('/first/:id', function ($id) {  
        echo "hello get route this is my $id program in slim";
    });

    /*post routes*/
    $app->post('/first', function () {  
        echo "hello post route";
    });

    //look in post we can't pass parameter through the URL bcz post can't take value from URL for give parameter use rest client app in chrome but this the resourse identifier will be same as above "/first" don't use "first/:id" bcz this is wrong way to pass parameter.
    $app->run(); // run

//now give the url like http://localhost/slim/index.php/ <-this is for get without parameter.
//http://localhost/slim/index.php/first/3 <-this is for get with parameter.
//http://localhost/slim/index.php/first  <-this is for post routes.

?> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM