RESTful resource handling and delete: controller method not found |
Hi all,
I created a controller User in a subfolder ('administration'): App/Controllers/Administration/User.php Acording to https://codeigniter4.github.io/userguide...stful.html, I added a route (config\routes.php): Code: $routes->resource('administration/user', ['placeholder' => '(:num)']); Within my User controller, I created the corresponding methods: PHP Code: <?php URI requests to: - http://localhost/administration/user/1/delete or - http://localhost/administration/user/delete/1 result in a '404 - File Not Found | Controller method is not found: user' error So it seems that the URI is not correctly translated to the /administration/user controller; user is seen as method... ![]() Can anyone help me with this weird issue? Many thanks in advance!
Are you using the proper HTTP verb when making the request? It looks like you need to use the DELETE verb to administration/user/1
Per the documentation, your resource declaration would do something like this: PHP Code: $routes->resource('administration/user', ['placeholder' => '(:num)']); (01-19-2022, 06:55 AM)xenomorph1030 Wrote: Are you using the proper HTTP verb when making the request? It looks like you need to use the DELETE verb to administration/user/1Hi xenomorph1030, Thanks for your reply. If I request administration/user/delete/<id>, it should be translated to the correct verb no? (Since I use $routes->resource()) Cheers, Zeff
It depends on how you are requesting it. Anything visited in a browser is a GET request. HTML forms are usually POST (method="post"). The other HTTP verbs (PUT, PATCH, DELETE) have to be specified in whatever library or application you are using to call it.
For example, if you are using Axios (common in VueJS), you can do something like: Code: axios.get(url, config) The advantage is you can use the same path (administration/user/1) for multiple operations depending on the HTTP verb. Per the resource you defined, there isn't suppose to be any administration/user/delete/1.
You can use websafe parameter in resource method
Resource routes PHP Code: $routes->resource('photos', ['websafe' => 1]); |
Welcome Guest, Not a member yet? Register Sign In |