Php Zend PSR7对流明不起作用?

Php Zend PSR7对流明不起作用?,php,zend-framework,lumen,psr-7,Php,Zend Framework,Lumen,Psr 7,Zend PSR7似乎对流明不起作用: use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response; // PSR 7 $app->bind('Psr\Http\Message\ServerRequestInterface', function ($app) { return (new Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory)

Zend PSR7似乎对流明不起作用:

use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response;

// PSR 7
$app->bind('Psr\Http\Message\ServerRequestInterface', function ($app) {
    return (new Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory)->createRequest($app->make('request'));
});

// PSR 7.
$app->get('hello/{name}', function (ServerRequestInterface $request) {

    // Interact with the PSR-7 request
    $name = $request->getAttribute('name');

    // var_dump($request->getHeaders());
    var_dump($name); // get NULL instead of 'world'

    // Interact with the PSR-7 response
    $response = new Response();
    $response->getBody()->write('Hello, ' . $name);

    return $response->withHeader('Content-type', 'application/json');
});
第一个“错误”:

var_dump($name); // get NULL instead of 'world'
第二个错误:

UnexpectedValueException in Response.php line 395:
The Response content must be a string or object implementing __toString(), "object" given.
in Response.php line 395
at Response->setContent(object(Response)) in Response.php line 54
at Response->setContent(object(Response)) in Response.php line 198
at Response->__construct(object(Response)) in Application.php line 1454
at Application->prepareResponse(object(Response)) in Application.php line 1314
at Application->callActionOnArrayBasedRoute(array('1', array(object(Closure)), array('name' => 'world'))) in Application.php line 1288
at Application->handleFoundRoute(array('1', array(object(Closure)), array('name' => 'world'))) in Application.php line 1262
at Application->handleDispatcherResponse(array('1', array(object(Closure)), array('name' => 'world'))) in Application.php line 1212
at Application->Laravel\Lumen\{closure}() in Application.php line 1442
at Application->sendThroughPipeline(array(), object(Closure)) in Application.php line 1213
at Application->dispatch(object(Request)) in Application.php line 1153
at Application->run(object(Request)) in index.php line 28
你知道为什么吗

Slim3似乎更简单、更直截了当

您可以尝试:

您可以尝试:


请将所有解释添加到您的答案中,而不是链接到外部资源请将所有解释添加到您的答案中,而不是链接到外部资源
$response = new \Shieldon\Psr7\Response();