2011-09-22 64 views
1

如何截断通过CakePHP中的Html Helper的链接?截断与CakePHP的链接

本书只截断文本字符串,但如何截断像这样的链接?

$this->Html->link('This is a very long link that needs to be truncated', '/pages/home', array('class' => 'button', 'target' => '_blank')); 

感谢

回答

6

结合使用与TextHelper :: truncate方法。例如:

$this->Html->link(
    $this->Text->truncate('This is a very long link that needs to be truncated'), 
    '/pages/home', 
    array('class' => 'button', 'target' => '_blank') 
); 
+0

非常感谢。我得到它的工作,我添加的唯一的东西是截断值<?php echo $ this-> Html-> link( $ this-> Text-> truncate('这是一个很长的链接,需要('class'=>'button','target'=>'_blank') ); 10), '/ pages/home', array; ?> – ChrisDK