Welcome Guest, Not a member yet? Register   Sign In
Over-engineering for a simple system
#4

(This post was last modified: 04-20-2020, 05:49 AM by BilltheCat.)

(04-20-2020, 01:24 AM)berendbotje91 Wrote: Perhaps not the best way to tackle your problem, but here is how I "check" the current page for the navigation.

You could load the current controller or method with something service('router')->controllerName(); then pass that to the navigation view as your current controller. Then all you need is
PHP Code:
class="nav-item <?= $Controller == 'admin' ? 'active' : ''; ?>" 
However, there currently (version 4.0.2) is an problem where the controllerName() function returns something different depending on wether the route is defined in routes.php: https://github.com/codeigniter4/CodeIgni...ssues/2520 so you might need some code to handle that.

Same can be done for ->methodName() if needed too.

This might decrease some php code in your view.

Thanks, but I'm not sure what you're doing different here than what I already have?

PHP Code:
class="nav-link <?= (uri_string() === 'admin/profile') ? 'active' : ''; ?>" 

(04-20-2020, 04:04 AM)InsiteFX Wrote: This might help you out, you may need to modify it a bit.

Highlight current page menu item with jQuery

Should point you in the right direction.
I don't know why I didn't think of JQuery for this...  thanks!
Reply


Messages In This Thread
RE: Over-engineering for a simple system - by BilltheCat - 04-20-2020, 05:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB