Welcome Guest, Not a member yet? Register   Sign In
Url segment in ci4
#6

(11-02-2019, 08:03 AM)donpwinston Wrote: In a controller:

$segment =  $this->request->uri->getSegment(1);

Thank you. This worked brilliantly.

I'm still relatively new to CI4, but the CI documentation does not explain segments well at all. The documentation says:

Quote:URI Segments

Each section of the path between the slashes is a single segment. The URI class provides a simple way to determine what the values of the segments are. The segments start at 1 being the furthest left of the path.

Code:
// URI = http://example.com/users/15/profile

// Prints '15'
if ($request->uri->getSegment(1) == 'users')
{
        echo $request->uri->getSegment(2);
}
 


But I cannot get the documentation's explanation working. The closest I got was an 'Out of range' error.  Huh
Reply


Messages In This Thread
Url segment in ci4 - by seunex - 11-02-2019, 01:41 AM
RE: Url segment in ci4 - by donpwinston - 11-02-2019, 08:03 AM
RE: Url segment in ci4 - by prikkles - 04-17-2020, 03:27 AM
RE: Url segment in ci4 - by Cathal - 09-01-2020, 07:46 PM
RE: Url segment in ci4 - by InsiteFX - 11-02-2019, 10:51 AM
RE: Url segment in ci4 - by wdeda - 11-08-2019, 06:58 PM
RE: Url segment in ci4 - by plaztic - 01-25-2020, 11:55 AM
RE: Url segment in ci4 - by demyr - 09-01-2020, 11:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB