GEOFFREY MWANGI GEOFFREY MWANGI - 20 days ago 7
PHP Question

Removing the href value in a yii2 link

I have a menu i have created in yii2 and i would like to remove the href value to #

This is what i have done

<?php
echo Menu::widget([
'encodeLabels' => false,
'options' => [
'class' => 'topnav menu-left-nest'
],
'items' => [
[
'label' => ThemeNav::link('Manager action, 'fa fa-user'),

'url' => ["#"], //this is the url {{i}}

'options' => ['class' => 'tooltip-tip'],
'items' => [

...items in the dropdown
],


When i check on the inspect element The above url ({{i}}) generates a value eg

<a href="/webwisekenya/advanced/backend/site/#"></a>


But i would like it to remain as

<a href="#"></a>


How do i go about this

This is the themenav class function link

public static function link($label, $icon = null) {

$link = null;

if (!empty($icon))
$link .= Html::tag('i','',['class'=>$icon]);

$link .= Html::tag('span', $label, []);

return $link;

}

Answer

In Item list spécification, url can be defined as array or string:

  • array: for predifined route
  • string: directly the url

url var is used with the function Url::to. More info here: http://www.yiiframework.com/doc-2.0/yii-helpers-baseurl.html#to()-detail

Manual about widget menu items: http://www.yiiframework.com/doc-2.0/yii-widgets-menu.html#$items-detail

Comments