关于breadcrumbs


1,给breadcrumbs加超链接

Php代码  
  1. $this->breadcrumbs=array(   
  2.     'Message'=>array('message/index'),    
  3.     'HelloWorld',   
  4. );  
$this->breadcrumbs=array(
	'Message'=>array('message/index'), 
    'HelloWorld',
);


2,给breadcrumbs修改首页为中文
我目前采用的是在config/main.php中设置为zh_ch,但还有另外一种解决办法,

Php代码  
  1. <?php   
  2. $this->widget('zii.widgets.CBreadcrumbs'array(   
  3.    'homeLink'=>CHtml::link('首页',Yii::app()->homeUrl),      
  4.     //这里可以修改HOME,变成中文   
  5.     'links'=>$this->breadcrumbs,   
  6. )); ?><!-- breadcrumbs -->  
<?php
$this->widget('zii.widgets.CBreadcrumbs', array(
   'homeLink'=>CHtml::link('首页',Yii::app()->homeUrl),   
    //这里可以修改HOME,变成中文
    'links'=>$this->breadcrumbs,
)); ?><!-- breadcrumbs -->


3,博客breadcrumbs使用
1,现在../components/controller.php中添加

Php代码  
  1. public $breadcrumbs=array();  
public $breadcrumbs=array();


2,在再../views/layouts/main.php

Php代码  
  1. <?php if(isset($this->breadcrumbs)):?>   
  2.         <?php $this->widget('zii.widgets.CBreadcrumbs'array('links'=>$this->breadcrumbs,)); ?>   
  3.     <?php endif?>  
<?php if(isset($this->breadcrumbs)):?>
		<?php $this->widget('zii.widgets.CBreadcrumbs', array('links'=>$this->breadcrumbs,)); ?>
	<?php endif?>


3,在具体页面中

Php代码  
  1. $this->breadcrumbs=array(   
  2.     'xx列表'=>array('index'),   
  3.     $model->workerName,   
  4. );  
$this->breadcrumbs=array(
	'xx列表'=>array('index'),
	$model->workerName,
);



二、关于createUrl和CHtml::link参数设置的区别
前者将多个参数放进一个数组中,后者直接向后累计添加(不放进数组)
1,createUrl应用

Html代码  
  1. <a href="<?php echo $this->createUrl('news/view',array('id'=>$companyNew->id,'news_type'=>$companyNew->news_type)) ?>" title="<?php echo $companyNew->title ?>">  
<a href="<?php echo $this->createUrl('news/view',array('id'=>$companyNew->id,'news_type'=>$companyNew->news_type)) ?>" title="<?php echo $companyNew->title ?>">


批注:在MVC中,可以使用$this->createUrl();在../components/xx.php中使用Yii::app()->createUrl();

2,CHtml::link应用

Html代码  
  1. <?php echo CHtml::link(CHtml::encode($data->title), array('view', 'id'=>$data->id,'news_type'=>$data->news_type)); ?>  
  2.   
  3. //例如:   
  4. <?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1'));?>  
  5. html输出是<a href="index.php?r=controller/action&param1=value1">Link Text</a>  
  6.   
  7. //多参数   
  8. <?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1','param2'=>'value2'));?>  
  9. html输出是<a href="index.php?r=controller/action&param1=value1&param2=value2">Link Text</a>  
  10.   
  11. //额外参数:   
  12. <?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1'), array('target'=>'_blank'));?>  
  13. html输出是<a target="_blank" href="index.php?r=controller/action&param1=value1">Link Text</a>  
  14.   
  15. //绝对路径:   
  16. <?php echo CHtml::link('Link Text', array('/controller/action'));?>  
  17.   
  18. //指定模块下的路径   
  19. <?php echo CHtml::link('Link Text', array('/module-id/controller/action'));?>  
  20.   
  21. //无效链接:   
  22. <?php echo CHtml::link('Link Text', array('href'=>'javascript:void(0)'));?>  
  23. <a href="javascript:void(0)">Link Text</a>  
<?php echo CHtml::link(CHtml::encode($data->title), array('view', 'id'=>$data->id,'news_type'=>$data->news_type)); ?>

//例如:
<?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1'));?>
html输出是<a href="index.php?r=controller/action&param1=value1">Link Text</a>

//多参数
<?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1','param2'=>'value2'));?>
html输出是<a href="index.php?r=controller/action&param1=value1&param2=value2">Link Text</a>

//额外参数:
<?php echo CHtml::link('Link Text', array('controller/action','param1'=>'value1'), array('target'=>'_blank'));?>
html输出是<a target="_blank" href="index.php?r=controller/action&param1=value1">Link Text</a>

//绝对路径:
<?php echo CHtml::link('Link Text', array('/controller/action'));?>

//指定模块下的路径
<?php echo CHtml::link('Link Text', array('/module-id/controller/action'));?>

//无效链接:
<?php echo CHtml::link('Link Text', array('href'=>'javascript:void(0)'));?>
<a href="javascript:void(0)">Link Text</a>




三、CHtml::linkButton
<?php echo CHtml::linkButton('LinkName', array('submit'=>array('controller/action','param'=>'value1'), 'confirm'=>"Are you sure?",));?>

posted @ 2012-12-28 16:39  -j神-----  阅读(550)  评论(0编辑  收藏  举报