unchanged
Title
By Example: CHtml
"By Example" cookbook pages will provide coding examples for many of
the commonly used classes within Yii. We will try to provide as many usage
examples as possible for keep these pages as helpful as possible.
## CHtml::link() method
~~~
[php]
public static string link(string $text, mixed $url='#', array $htmlOptions=array
( ))
~~~
Generates a hyperlink tag.
***
### Example 1: Linking to a controller action
~~~
[php]
<?php echo CHtml::link('Link
Text',array('controller/action'));Text',array('controller/action')));
?>
~~~
#### HTML Output:
~~~
[php]
<a href="index.php?r=controller/action">Link Text</a>
~~~
***
### Example 2: Linking to a controller action with querystring parameters
~~~
[php]
<?php echo CHtml::link('Link Text',array('controller/action',
'param1'=>'value1'));'param1'=>'value1'))); ?>
~~~
#### HTML Output:
~~~
[php]
<a href="index.php?r=controller/action¶m1=value1">Link
Text</a>
~~~
***
### Example 3: Linking to a controller action with multiple querystring
parameters
~~~
[php]
<?php echo CHtml::link('Link Text',array('controller/action',
'param1'=>'value1',
'param2'=>'value2',
'param3'=>'value3'));'param3'=>'value3'))); ?>
~~~
#### HTML Output:
~~~
[php]
<a
href="index.php?r=controller/action¶m1=value1¶m2=value2¶m3=value3">Link
Text</a>
~~~