Welcome Guest, Not a member yet? Register   Sign In
put method not working
#1

I have this route for update my user data:

PHP Code:
$routes->put('/admin/users/(:num)/update''Admin\UserController::update/$1', ['as' => 'update']); 

in  UserController:

PHP Code:
    public function update(int $id){
        echo 'Ok';
    

in View:

PHP Code:
<form method="PUT" action="<?= route_to('update', esc($user['id'])); ?>" 


But in Action i see error:

Code:
404 - File Not Found

Controller or its method is not found: {0}::{1}


How do can i fox this problem?
Reply
#2

Have you checked the generated source code for your action="". Where does it go?
Reply
#3

(03-21-2020, 07:51 AM)jreklund Wrote: Have you checked the generated source code for your action="". Where does it go?

Yes, when i change/replace put to post(in routes and form action) every thing is ok and work but in put method i see this error.
Reply
#4

HTML forms don't really do PUT requests. PUT requests are typically handled through AJAX requests, but CI4 does provide HTTP method spoofing you can use with your forms to emulate it. Note, that it's still a POST request and any request variables would still be accessible through $_POST, not the request body like an actual PUT request would do.
Reply
#5

Well, that may be so. But I can't seem to make a put request using jquery (type = PUT) either. The docs aren't to clear on how to actually 'use' what it tries to explain. I set a route (… ->put …) and expect to be able to do 'automatic' updates on resources, as that's the impression I get from reading up on "RESTful Resource Handling" ...

Could you maybe be a bit clearer on the full 'lifecycle' – if you will – on how to properly implement a RESTFul API using the provided 'tools' in CI4? What would be nice is a set of routes matched to a set of methods, matched to a set of url requests with the corresponding data set properly using the matched HTTP methods. It seems I have to do A LOT of assembling the puzzle pieces myself ... to much is assumed, I guess.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB