How to read PUT and DELETE request using codeigniter framework?

I am creating an API server using codeigniter framework and I was wondering if it is possible to read PUT and DELETE requests from any client side form submissions?

The user guide doesn't explain much regarding this.

2 answers

  • answered 2018-07-12 07:22 Archangels

    You can try to detect the method type first and seperate the different cases:

    switch($_SERVER['REQUEST_METHOD']){
       case 'GET':
    
          ...
          break;
       case 'POST':
    
          ...
          break;
       case 'PUT':
    
          ...
          break;
       case 'DELETE':
    
          ...
          break;
       default:
          echo "Unknown Request.";
    }
    

  • answered 2018-07-12 07:26 deadman

    The HTML standard does not support PUT inside the <form method=""> attribute and also browser doesn't support it. Browsers don't generally support methods other than GET and POST in HTML forms. if you put anything else other than POST or GET it should be sent as a GET request according to specification.

    Use hidden method field in your form and put the actual HTTP.Use this library