getting array of uri segments excluding subdirectory in base_url() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: getting array of uri segments excluding subdirectory in base_url() (/showthread.php?tid=81817) |
getting array of uri segments excluding subdirectory in base_url() - dgvirtual - 05-02-2022 I am trying to find an optimal way to get an array of segments of the uri of my application that would not include the subdirectory where my app resides, if I use such (I do in production, but not in the development env). Previously I have used code that would check the first segment against a keyword, and if it matches (which means my base_url includes a subdirectory), the first segment gets ignored: PHP Code: $uri = current_url(true); It is cumbersome and depends on the name of the directory, which might change between projects, so I was looking for alternative. Was playing with this code: PHP Code: $uri = trim(uri_string(false),'/'); However, I wonder if there are any caveats to my new approach. Any ideas? Or maybe there is a better, codeigniter'ish, way of doing it? } RE: getting array of uri segments excluding subdirectory in base_url() - JustJohnQ - 05-02-2022 Why not use: PHP Code: $segments = $uri->getSegments(); RE: getting array of uri segments excluding subdirectory in base_url() - dgvirtual - 05-03-2022 (05-02-2022, 11:59 PM)JustJohnQ Wrote: Why not use: Well, because in case the url is https://mywebsite.com/appsubdir/firstseg/secondseg it returns Code: Array while in my development environment, with url like http://localohost:8080/firstseg/secondseg (no app subdirectory) it returns Code: Array And I need a universal way, independent of the name of the app subdirectory or it's absence, to get the array: Code: Array |