I just started migrating from laravel to yii2
In Laravel, I had a moment when I checked the current route, and if we are on this page, then we leave only the text, and if not, then we make this text a link
@if(Route::currentRouteName() === 'contact')
<span class="contact-link active">contact</span>
@else
<a href="{{ route('contact') }}" class="contact-link">contact</a>
@endif
Now I want to do exactly the same on yii2
With a regular link, everything is clear
<a href="<?= Url::to(['/contact']) ?>" class="contact-link">contact</a>
But how can you check the current page?
My controller
public function actionIndex()
{
return $this->render('contact');
}
3
Answers
Assuming the action in your controller is named
contact
, you could do the following:You can call
getUniqueId()
on currently active action:or use
$id
property if you want "relative" ID of current action:get current
controller name:
current
action name:
current
route:
This code can help you. Or you can modify your code based on current route.