<?php
namespace common\helpers;
use Yii;
class ActiveLink
{
/**
* Проверка на controller
*
* @param $name
* @param $class
* @return string
*/
public static function controller($name, $class) {
if ( Yii::$app->controller->id === $name ) {
return $class;
}
return '';
}
/**
* Проверка на controller/action
*
* @param $name
* @param $class
* @return string
*/
public static function route($name, $class) {
if ( Yii::$app->controller->route === $name ) {
return $class;
}
return '';
}
}
<div class="sidebar__nav-list">
<a href="<?= URL::toRoute('info/info') ?>" class="sidebar__nav-item <?= ActiveLink::controller('info', 'sidebar__nav-item_active') ?>">
<img src="/admin/images/sidebar/info.png" class="sidebar__icon-item">
</a>
<a href="<?= URL::toRoute('news/news') ?>" class="sidebar__nav-item <?= ActiveLink::controller('news', 'sidebar__nav-item_active') ?>">
<img src="/admin/images/sidebar/news.png" class="sidebar__icon-item">
</a>
</div>