Welcome Guest, Not a member yet? Register   Sign In
How do I send the second segment as id to update method?
#1

I 'think' I need to pass a different segment to the UPDATE method on the model in an attempt to update a resource (RESTFully).

According to the docs:
Code:
Change the Placeholder Used

$routes->resource('photos', ['placeholder' => '(:num)']);

// Generates routes like:
$routes->get('photos/(:num)', 'Photos::show/$1');

But in my case the resource ('photos') is dynamic, so I need to pass segment AFTER the first 'segment' as I guess CI sees it as a segment because it's dynamic.

Are there ANY mechanisms for working with the segment in the route, and what I pass to the method – update in this case?
Reply
#2

(12-15-2020, 05:47 AM)blaasvaer Wrote: I 'think' I need to pass a different segment to the UPDATE method on the model in an attempt to update a resource (RESTFully).

According to the docs:
Code:
Change the Placeholder Used

$routes->resource('photos', ['placeholder' => '(:num)']);

// Generates routes like:
$routes->get('photos/(:num)', 'Photos::show/$1');

But in my case the resource ('photos') is dynamic, so I need to pass segment AFTER the first 'segment' as I guess CI sees it as a segment because it's dynamic.

Are there ANY mechanisms for working with the segment in the route, and what I pass to the method – update in this case?

The routes file is parsed top to bottom so you can alway override defined routes. If you put a separate get() with two arguments after your resource() definition it will match that. If you always have two arguments, you can look into the "except" option to resource() to not define certain functions.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB