I am currently using following syntax in menu in default.ctp of my CakePHP 3 application
<li class="first"><a href="<?php echo $url; ?>users/dashboard"><span class="glyphicon glyphicon-th-list"></span><br>Dashboard</a></li>
Now the problem arises if I try to write the tag in CakePHP 3 syntax which is as follows:
<li><?php echo $this->Html->link('Dashboard',['controller'=>'Users', 'action'=>'view','_full'=>true]);?></li>
As you can see that there is no place to put tag in above and because of that glyph disappear from menu.
Is there a way around that which I can't find?
Use 'escape' => false
to solve your problem
<li>
<?php
echo $this->Html->link(
'<span class="glyphicon glyphicon-th-list"></span><br>Dashboard',
array('controller'=>'Users', 'action'=>'view','_full'=>true),
array('escape' => false) // important
);
?>
</li>
For cakephp 3
<?php
echo $this->Html->link(
'<span class="glyphicon glyphicon-th-list"></span> <br>Dashboard',
['controller'=>'Users', 'action'=>'index','_full'=>true],
['escape' => false] // important
);
?>
If you are not getting along with the HTML link helper, you can use shorter way, less php code Url Helper
<?= $this->Url->build(['controller'=>'Users', 'action'=>'view','_full'=>true]); ?>
And create menu / html link as
<li class="first">
<a href="<?= $this->Url->build(['controller'=>'Users', 'action'=>'view','_full'=>true]); ?>">
<span class="glyphicon glyphicon-th-list"></span>
Dashboard
</a>
</li>
Use escapeTitle
option.
$this->Html->link(
'<span class="glyphicon glyphicon-th-list"></span><br>Dashboard',
['controller'=>'Users', 'action'=>'view','_full'=>true],
['escapeTitle' => false]
);
Try using:
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-th-list')) . "Dashboard",
array('controller' => 'users', 'action' => 'view'),
array('escape'=>false)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.