phpyiiyii-componentsyii-chtml

How to use CHtml::link(); inside "<li></li>" in Yii?


I need to use CHtml::link() inside " ".

Here is my existing code:

    $html .="<li>\n <a href='books".$menu['items'][$itemId]['link']."'>
                     ".$menu['items'][$itemId]['label']."
                    </a> \n";

    $html .= buildMenutree($itemId, $menu);

    $html .= "</li> \n";

I hope I can find a nice solution.


Solution

  • You can use the CHtml function in your string just as any other PHP function:

    $html .="<li>\n " . CHtml::link($menu['items'][$itemId]['label'], $menu['items'][$itemId]['link']);
    

    See normalizeUrl for the url's you can use.