Welcome Guest, Not a member yet? Register   Sign In
How to force POST verb only for action method
#1

[eluser]deepakaggarwal[/eluser]
I've a method in controller which I want to respect only POST requests. If its a GET request it should actually be 404 Not found. How can I accomplish this?

thanks
#2

[eluser]pickupman[/eluser]
How about checking to see if the _POST array is greater than 1 otherwise show_404().
#3

[eluser]Sagar Ratnaparkhi[/eluser]
Yes, you can do it like

Code:
if(!empty($this->input->get()) && count($this->input->get()) > 0 )
  show_404();
#4

[eluser]deepakaggarwal[/eluser]
I did
Code:
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    show_404();
}
else
{
//my code
}
thanks all!

Reason I was looking for this: I want to have a controller which displays form when GET otherwise performs operation. For example, GET:// AddUser() will display new user form while POST:// AddUser() will perform operation and display thank you. This will help me in having one action method and play with verbs.




Theme © iAndrew 2016 - Forum software by © MyBB