Yii (1.1.11)の最新バージョンを使用している場合、CBreadcrumbsにいくつかの新しいオプションがあります。activeLinkTemplate
inactiveLinkTemplate
tagName
これらのオプションの値を追加する必要があるだけです。ブレッドクラム ウィジェットをインクルードしているファイルに、デフォルトでは、次のようにレイアウト ファイル: 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?>
'activeLinkTemplate'
アクティブ/クリック可能なリンクのリンクを'inactiveLinkTemplate'
生成し、クリック可能ではなく、URL を持たない現在の URL を生成します。
{url}
と{label}
は、各ビューのパンくずオブジェクトによって提供されるURLとラベルの値です。例えば:-
// in some view.php file, you'll see this
$this->breadcrumbs=array( // array is label=>url
'Label1'=>array('route1'),
'Label2'=>array('route2'),
'Label3',
);
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 -->