Welcome Guest, Not a member yet? Register   Sign In
trailing slash misdirects resource controller
#1

when specifying a resource route according to the user guide:
PHP Code:
$routes->resource('photos'); 
the create() controller method is correctly called when POSTing data to /photos, however when a trailing slash is added /photos/ the index() controller method is called instead


adding a route like
PHP Code:
$routes->post('users/''Users::create');
$routes->resource('users'); 
before the resource route doesn't help
Reply
#2

This is because a URL ending with a trailing slash is treated as a directory, not a file.

This applies to all URLs in general, not only in API or CodeIgniter as a whole.

https://en.ryte.com/wiki/Trailing_Slashe...20a%20file.
Reply
#3

sorry, I don't see how it makes a POST request to /photos/ equivalent to a GET request to /photos in a REST resource. Seems like now I need to manually add a check if index() has been called with the incorrect method and return 404
Reply




Theme © iAndrew 2016 - Forum software by © MyBB