• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.