我需要修改Yii框架widget-zii.widgets.CBreadcrumbs.默认情况下会打印:
<div class="breadcrumbs">
<a href="/dr/dr/public_html/">Home</a> » <span>News</span></div>
Run Code Online (Sandbox Code Playgroud)
但是我需要:
<ul class="menu">
<li><a href="/dr/dr/public_html/">Home</a></li>
<li>News</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
那么我怎么能改变呢?
boo*_*dev 13
如果您使用的是最新版本的Yii的(1.1.11) ,那么你有几个新选项CBreadcrumbs,即:activeLinkTemplate与inactiveLinkTemplate和使用这些(也tagName)就可以轻松实现您的要求.
您只需要在包含breadcrumb小部件的文件中添加这些选项的值,默认情况下,它位于布局文件中:protected/views/layouts/main.php,如下所示:
<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'tagName'=>'ul', // will change the container to ul
'activeLinkTemplate'=>'<li><a href="{url}">{label}</a></li>', // will generate the clickable breadcrumb links
'inactiveLinkTemplate'=>'<li>{label}</li>', // will generate the current page url : <li>News</li>
'homeLink'=>'<li><a href="'.Yii::app()->homeUrl.'">Home</a></li>' // will generate your homeurl item : <li><a href="/dr/dr/public_html/">Home</a></li>
)); ?><!-- breadcrumbs -->
<?php endif?>
Run Code Online (Sandbox Code Playgroud)
'activeLinkTemplate'生成活动/可点击链接的链接,并'inactiveLinkTemplate'生成不可点击且没有网址的当前网址.
{url}并且{label}是每个视图的痕迹导体对象提供的url和label值.例如:-
// in some view.php file, you'll see this
$this->breadcrumbs=array( // array is label=>url
'Label1'=>array('route1'),
'Label2'=>array('route2'),
'Label3',
);
Run Code Online (Sandbox Code Playgroud)如果您使用的是1.1.11之前的版本,那么您将必须extend使用CBreadcrumbs类并修改run()方法以输出包含在其中的面包屑<li>.一旦你看到现有的run()方法,它将变得相当清楚你如何做到这一点.
编辑:
错过了如何添加css类.您可以通过在此小部件的htmlOptions数组中添加类键值来完成此操作:
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'tagName'=>'ul', // will change the container to ul
'htmlOptions'=>array('class'=>'menu'),
// ... rest of the code ...
)); ?><!-- breadcrumbs -->
Run Code Online (Sandbox Code Playgroud)