CodeIgniter Forums

Full Version: How to use $request->uri->getSegment() inside view?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to use `$ request-> uri-> getSegment (1)` in the view but I get an error saying "Undefined variable: request", what should I do to display a given segment in the view?
(06-20-2020, 11:02 AM)0x0undefined Wrote: [ -> ]I'm trying to use `$ request-> uri-> getSegment (1)` in the view but I get an error saying "Undefined variable: request", what should I do to display a given segment in the view?

I use this, in Model:
PHP Code:
$request = \Config\Services::request();
        $uri $request->uri;
        $id $uri->getSegment(3);