core
core copied to clipboard
Flight::json with Flight::after('start'...
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.
Could you please share code related to this issue?
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.
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.
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.
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.
Did you try changing the line: Flight::after('start', function() {
To: Flight::after('start', function(&$params, &$output) {
didnt help :(((
wrapping the response in exit() makes it work. exit(Flight::json(array('id' => 123)));
any issue with doing that?
Is this still actual?
If you still have this issue, go ahead and reopen this, otherwise we'll close it for now.