# in a CakePHP $this->Html->link


# in a CakePHP $this->Html->link

我想知道如何在不转义的情况下将"#"添加到cakefp url中。我试过逃跑,但没有成功。我这样做是为了尝试链接到包含评论的页面的id="comments"部分。这是我的链接代码:

<?php echo $this->Html->link($post['Post']['total_comments'].' comments', array('controller' => 'posts', 'action' => 'view', $post['Post']['slug'].'#comments'),array('class' => 'comments-icon')); ?>

如有任何帮助,我们将不胜感激。

试试这个:

echo $this->Html->link($post['Post']['total_comments'].' comments', array(
       'controller' => 'posts', 
       'action' => 'view', 
       $post['Post']['slug'], 
       '#' => 'comments' //Or #comments only without key
      ), array('class' => 'comments-icon'));