Is there a way to get the current method arguments? |
I am using this static pages controller from the documentation with this route definition:
PHP Code: // static pages I am adding a css class on the links to existing pages in my navigation. For most of the links I can easily test the name of the controller, but for the static pages, I need to know which page is called. Is there a way to get that value? (I experimented with getMatchedRoute(); and it looks like I can get from one of the array value the full route, eg Code: \App\Controllers\PagesController::show/about but I was wondering if there was a way to get the argument directly?
Try URI object? site.com/profile/103 See segments array
PHP Code: $this->request->getUri()->getSegments() Code: array:2 [▼ Code: CodeIgniter\HTTP\SiteURI {#25 ▼
Thanks @ozornick. In the end, here's what I did inside a helper:
PHP Code: function isCurrentMenu(){ And in my view, on the links where I need the CSS class, I call it like that: Code: <a href="" class="<?= isCurrentMenu() == 'about' ? 'current' : '' ; ?>">about</a> Not sure it is the best way, but it does what I need |
Welcome Guest, Not a member yet? Register Sign In |