flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.62k stars 409 forks source link

Flight::json with Flight::after('start'... #450

Closed threethousand closed 7 months ago

threethousand commented 3 years ago

I have a filter after start, that updates a session cookie.

I have a route that returns Flight:json() and if the filter is active, nothing is returned for this route. connection just dies according to firefox. If the filter is removed, the json response for said route works perfect. what is that? or rather, how do i fix it?

edit* echo json_encode(....) instead of Flight::json works fine as well with the filter running after start.

magikstm commented 3 years ago

Could you please share code related to this issue?

threethousand commented 3 years ago

Flight::after('start', function() { Flight::serviceSession()->reload(); }

Flight::route('POST /account', array('actionAccount','main'));

class actionAccount { public static function main() { Flight::json(array('id' => 123)); } }

serviceSession()->reload function reloads a cookie. but even if i clear the whole function, things still break.

magikstm commented 3 years ago

json_encode is used by the framework: https://github.com/mikecao/flight/blob/master/flight/Engine.php#L501

The method you are using is used to send a response: https://github.com/mikecao/flight#json

This can be used to retrieve it: https://github.com/mikecao/flight#json-input

What is the exact error in Firefox? Did you try Chrome?

I don't see an issue with code above at the moment.

threethousand commented 3 years ago

yes, i want to send a response, not retrieve. im gonna have to keep digging but its so weird.

firefox says: "Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc." and the response is none i guess, its totally empty.

thank you for taking time.

threethousand commented 3 years ago

its something to do with Flight::after('start', because if i move the "Flight::serviceSession()->reload();" call into the actionAccount','main') function, and the contents of said function only is: public static function main() { Flight::serviceSession()->reload(); Flight::json(array('id' => 123)); }

then it works.

magikstm commented 3 years ago

Did you try changing the line: Flight::after('start', function() {

To: Flight::after('start', function(&$params, &$output) {

threethousand commented 3 years ago

didnt help :(((

threethousand commented 3 years ago

wrapping the response in exit() makes it work. exit(Flight::json(array('id' => 123)));

any issue with doing that?

krmu commented 7 months ago

Is this still actual?

n0nag0n commented 7 months ago

If you still have this issue, go ahead and reopen this, otherwise we'll close it for now.