0

I'm trying to match the current url a user is on to a route, and output an 'active' class if the route matches:

<?php if($this->url() == $this->url('dashboard')) echo "class='active'" ?>

This works on routes that exist. However, this will mess up 404 routing; if I go to a route that doesn't exist, i.e. localhost/someurl, I get:

Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'No RouteMatch instance provided'

What is the best way to go about this?

4

1 回答 1

0

你试试:

控制器:

public function dashboardAction(){
    return new ViewModel(array(
            'dashboard' => true,
    ));
}

看法:

<div class="<?php echo $this->dashboard ? 'active' : ''?> other-class">Dashboard</div>

祝你好运。:D

于 2013-11-01T16:25:08.390 回答