-1

I am new to slim and I want to pass Data between two routes (apps)

$app->get('/answer', function (Request $request, Response $response) use($talk,$voiceName,$message){

    // submit this data
    $request = $request->withAttribute('username','XXXXXX');

    return $response->withJson($ncco);
});


$app->post('/webhooks/comfrimcardinput', function (Request $request, Response $response, $args) use($talk,$voiceName,$message){

    //  Get this data
    $foo = $request->getAttribute('username');

    return $response->withJson($ncco);
});
YakovL
  • 7,557
  • 12
  • 62
  • 102

1 Answers1

-1

If i understand your question correctly, you want to pass information/data between two routes that get called individually.

Since the request and response objects are generated for each route and only available in the context of that route, it is not possible to attach data to that objects that will persist through page-loads/sessions.

You need to use some kind of storage for persistent data. There are several options for you available. Some store the information server-side, others store them in the browser/client-side. Which one the best solution for your use-case is depends on the kind of data you want to store.

Server-side:

  • Files
  • Database

Client-side:

  • sessionStorage (only available from javascript)
  • localStorage (only available from javascript)
  • Cookies (available from php & javascript)

Cookies in PHP:

// write a cookie
setcookie("TestCookie", $value, time()+3600);  /* valid for 1 hour (3600 secods) */

// read a cookie
$value = $_COOKIE["TestCookie"];

More Information on cookies in PHP: setcookie, $_COOKIE

Jan
  • 2,853
  • 2
  • 21
  • 26