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

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.
Reply


Messages In This Thread
RE: Over-engineering for a simple system - by berendbotje91 - 04-20-2020, 01:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB