Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use GET request? #30

Open
firestorm23 opened this issue Nov 13, 2015 · 10 comments
Open

How to use GET request? #30

firestorm23 opened this issue Nov 13, 2015 · 10 comments

Comments

@firestorm23
Copy link

Suddenly I realised that docs have no clue how to declare a GET method when generating link_to().

Tried to reverse searching the source .js, but it didnt help. I see that it contains processing of method parameter but I somehow dont understand how to declare it.

@firestorm23
Copy link
Author

I seem to get what the problem is.

810 line of code contains declaring of "method" varible which came from "phery" arguments of generated link, but it's never used.

I had to manually change the source by pasting it into 1006 line, where "type" parameter of generic ajax function is declared.

It was hardcoded as just "POST".

@firestorm23
Copy link
Author

Please consider this in the future releases.

@pocesar
Copy link
Contributor

pocesar commented Nov 13, 2015

hey @firestorm23 it seems that it's left out of docs indeed. to generate a request with a METHOD_OVERRIDE using link_to, needs to set the 'method' attribute:

Phery::link_to('Click me', 'remote', array('method' => 'GET'));

Although the request will still be sent as a POST to the server, there will be an added HTTP header with X-HTTP-Method-Override: GET

@firestorm23
Copy link
Author

Oh, I see. Thank you for pointing out about header. Looks like this feature makes it more tricky to use with Symfony Framework, because it ignores this header if the app is behind HTTP caching.

@firestorm23
Copy link
Author

Still, consider this. Something tells me that this header is not popular, so your solution could be given up by those who had problem with this issue. By the way it is great, integreated it with Symfony Request/Response, and it works great without duplicating code in Controller and Views.

@pocesar
Copy link
Contributor

pocesar commented Nov 14, 2015

I don't know Symfony, but doesn't this solve the problem? http://api.symfony.com/2.7/Symfony/Component/HttpFoundation/Request.html#method_enableHttpMethodParameterOverride

The issue with using non-POST is that you can't mix file uploads with data, and phery does this by default, either by sending the entire form or a file input along with arbitrary data

@firestorm23
Copy link
Author

Yes, this method should work according to what i read. I'll try it.

@firestorm23
Copy link
Author

Returning to this issue. I actually found that no sign of sending X-HTTP-Method-Override in the source code nor catching it in the browser or server was found.

@firestorm23
Copy link
Author

In the current phery.js '_headers' object that is sent, does not contain instructions to contain X-HTTP-Method-Override header. It's in 801-804 lines.

@pocesar
Copy link
Contributor

pocesar commented Dec 15, 2015

you're right, the info actually comes in the second parameter on the callback:

Phery::instance()->set([
   'postAsGet' => function($data, $pheryData) {
      $pheryData['method'] === 'GET'
   }
])->process();
<div>
<?php echo Phery::link_to('click me', 'postAsGet', ['method' => 'GET']); ?>
</div>

I should change it to use HTTP override, it's the proper way (You see, I thought of this, but didn't make the change yet)

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

No branches or pull requests

2 participants