Yii 链接-如何添加html类?

Yii 链接-如何添加html类?,yii,Yii,在文档中,我们可以阅读: public static string link(string $text, mixed $url='#', array $htmlOptions=array ( )) 问题: 我不明白$htmlOptions在这里意味着什么。我不明白如何从这个表示形式传递到真正的代码 任何人都可以提供一个例子,说明我们如何生成一个定义了类的链接。 比如: <a href="#" class="hello">link hello</a> 这比你想象的要容易

在文档中,我们可以阅读:

public static string link(string $text, mixed $url='#', array $htmlOptions=array ( ))
问题: 我不明白$htmlOptions在这里意味着什么。我不明白如何从这个表示形式传递到真正的代码

任何人都可以提供一个例子,说明我们如何生成一个定义了类的链接。 比如:

<a href="#" class="hello">link hello</a>

这比你想象的要容易,尽管Yii的文档可能比需要的要复杂一些。但是,它确实指出,
$htmlOptions

其他HTML属性。除了正常的HTML属性外,还有一些 还可以识别特殊属性(有关详细信息,请参见clientChange和标记 (更多详情。)

本质上,您放入数组中的任何键/值对都将显示为HTML属性。所以,你想做的是

CHtml::link('link hello', '#', array('class' => 'hello'));
“”“除了文档引用的“特殊”值之外,这些值最终不会以HTML形式呈现,而是会稍微修改
链接的工作方式,或者以其他方式影响HTML。


<?php echo CHtml::link('Link Text',array('controller/action','param1'=>'value1'), array('target'=>'_blank','class'=>'hello'); ?>


<!--if you disabled url manager in "protected/config/main.php" the output will be -->
<a target="_blank" class="hello" href="index.php?r=controller/action&param1=value1">Link Text</a>

<!--if you enabled url manager in "protected/config/main.php" the output will be -->
<a target="_blank" class="hello" href="controller/action/param1/value1">Link Text</a>
<?php echo CHtml::link("Label Text" , array("/controller_here/action_here") , array('class' => 'class_here')); ?>
<?php echo CHtml::link("Label Text" , Yii::app()->createUrl("/controller_here/action_here") , array('class' => 'class_here')); ?>