如何使用Chtml :: link
在Yii框架中获取此信息<a href="#" title="Movie 1" class="search-movie"><img alt="Movie 1" src="../../images/1.jpg"><p>Movie 1</p></a>
当我这样做时,
<?php $imghtml=CHtml::image('../../images/1.jpg');
echo CHtml::link($imghtml, array('moviepage/index'),array('class'=>'search-movie', 'title'=>'Movie 1'));?>
我只有
<a href="#" title="Movie 1" class="search-movie"><img alt="Movie 1" src="../../images/1.jpg"></a>
答案 0 :(得分:3)
生成链接时需要包含标题的标记:
<?php
$imghtml=CHtml::image('../../images/1.jpg');
$caption = CHtml::tag('p', array(), 'Movie 1');
echo CHtml::link("{$imghtml}{$caption}", array('moviepage/index'), array('class'=>'search-movie', 'title'=>'Movie 1'));
?>
答案 1 :(得分:2)
像这样:
<?php $imghtml=CHtml::image('../../images/1.jpg');
echo CHtml::link("$imghtml<p>Move 1</p>", array('moviepage/index'),array('class'=>'search-movie', 'title'=>'Movie 1'));?>