Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Access GET/POST params in Swoole #136

Closed
bilabar opened this issue Jan 8, 2019 · 1 comment
Closed

Access GET/POST params in Swoole #136

bilabar opened this issue Jan 8, 2019 · 1 comment
Assignees
Labels

Comments

@bilabar
Copy link

bilabar commented Jan 8, 2019

Hi Leo,

Yesterday, I tried to use Siler with Swoole. It's great. Alas, I can't access GET or POST params when I used files base route.

index.php

Route\get('/3', 'controller.php', Swoole\cast($req))

controller.php

var_dump($params) // array for route [0] => 3
var_dump($req, $res) // error
var_dump(\Siler\Http\Request\get()) // null

Is there any way to access it?

@leocavalcante
Copy link
Owner

Hi @bilabar
Awesome! Thanks for the interest of using Siler within Swoole!
You're right, there is no trivial way to handle Swoole's request and response objects when requiring files, that is why I changed the labels from question to bug.

To solve that, I added at Swoole namespace the functions: request, response and emit. They internally stores the current Request and Response objects and exposes getters for them.

So at controller.php you can:

use Siler\Swoole;
$req = Swoole\request();
$req->get['param'];

For responses, you should favor Swoole\emit instead of calling the end() method on the Response object:

Swoole\emit('Created', 201);

I'm working on the documentation, but you can take a look at:
https://github.com/leocavalcante/siler/tree/master/examples/swoole
To see more about that.

Hope it helps, ping me back on any issues!

PS.: use "leocavalcante/siler": "dev-master" while I prepare a new release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants