PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/zii/widgets/CBreadcrumbs.php

https://bitbucket.org/rezanachmad/php-selenium-training
PHP | 132 lines | 35 code | 3 blank | 94 comment | 4 complexity | 881a149266df96d9176504a14c33de93 MD5 | raw file
  1. <?php
  2. /**
  3. * CBreadcrumbs class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CBreadcrumbs displays a list of links indicating the position of the current page in the whole website.
  12. *
  13. * For example, breadcrumbs like "Home > Sample Post > Edit" means the user is viewing an edit page
  14. * for the "Sample Post". He can click on "Sample Post" to view that page, or he can click on "Home"
  15. * to return to the homepage.
  16. *
  17. * To use CBreadcrumbs, one usually needs to configure its {@link links} property, which specifies
  18. * the links to be displayed. For example,
  19. *
  20. * <pre>
  21. * $this->widget('zii.widgets.CBreadcrumbs', array(
  22. * 'links'=>array(
  23. * 'Sample post'=>array('post/view', 'id'=>12),
  24. * 'Edit',
  25. * ),
  26. * ));
  27. * </pre>
  28. *
  29. * Because breadcrumbs usually appears in nearly every page of a website, the widget is better to be placed
  30. * in a layout view. One can define a property "breadcrumbs" in the base controller class and assign it to the widget
  31. * in the layout, like the following:
  32. *
  33. * <pre>
  34. * $this->widget('zii.widgets.CBreadcrumbs', array(
  35. * 'links'=>$this->breadcrumbs,
  36. * ));
  37. * </pre>
  38. *
  39. * Then, in each view script, one only needs to assign the "breadcrumbs" property as needed.
  40. *
  41. * @author Qiang Xue <qiang.xue@gmail.com>
  42. * @package zii.widgets
  43. * @since 1.1
  44. */
  45. class CBreadcrumbs extends CWidget
  46. {
  47. /**
  48. * @var string the tag name for the breadcrumbs container tag. Defaults to 'div'.
  49. */
  50. public $tagName='div';
  51. /**
  52. * @var array the HTML attributes for the breadcrumbs container tag.
  53. */
  54. public $htmlOptions=array('class'=>'breadcrumbs');
  55. /**
  56. * @var boolean whether to HTML encode the link labels. Defaults to true.
  57. */
  58. public $encodeLabel=true;
  59. /**
  60. * @var string the first hyperlink in the breadcrumbs (called home link).
  61. * If this property is not set, it defaults to a link pointing to {@link CWebApplication::homeUrl} with label 'Home'.
  62. * If this property is false, the home link will not be rendered.
  63. */
  64. public $homeLink;
  65. /**
  66. * @var array list of hyperlinks to appear in the breadcrumbs. If this property is empty,
  67. * the widget will not render anything. Each key-value pair in the array
  68. * will be used to generate a hyperlink by calling CHtml::link(key, value). For this reason, the key
  69. * refers to the label of the link while the value can be a string or an array (used to
  70. * create a URL). For more details, please refer to {@link CHtml::link}.
  71. * If an element's key is an integer, it means the element will be rendered as a label only (meaning the current page).
  72. *
  73. * The following example will generate breadcrumbs as "Home > Sample post > Edit", where "Home" points to the homepage,
  74. * "Sample post" points to the "index.php?r=post/view&id=12" page, and "Edit" is a label. Note that the "Home" link
  75. * is specified via {@link homeLink} separately.
  76. *
  77. * <pre>
  78. * array(
  79. * 'Sample post'=>array('post/view', 'id'=>12),
  80. * 'Edit',
  81. * )
  82. * </pre>
  83. */
  84. public $links=array();
  85. /**
  86. * @var string String, specifies how each active item is rendered. Defaults to
  87. * "<a href="{url}">{label}</a>", where "{label}" will be replaced by the corresponding item
  88. * label while "{url}" will be replaced by the URL of the item.
  89. * @since 1.1.11
  90. */
  91. public $activeLinkTemplate='<a href="{url}">{label}</a>';
  92. /**
  93. * @var string String, specifies how each inactive item is rendered. Defaults to
  94. * "<span>{label}</span>", where "{label}" will be replaced by the corresponding item label.
  95. * Note that inactive template does not have "{url}" parameter.
  96. * @since 1.1.11
  97. */
  98. public $inactiveLinkTemplate='<span>{label}</span>';
  99. /**
  100. * @var string the separator between links in the breadcrumbs. Defaults to ' &raquo; '.
  101. */
  102. public $separator=' &raquo; ';
  103. /**
  104. * Renders the content of the portlet.
  105. */
  106. public function run()
  107. {
  108. if(empty($this->links))
  109. return;
  110. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  111. $links=array();
  112. if($this->homeLink===null)
  113. $links[]=CHtml::link(Yii::t('zii','Home'),Yii::app()->homeUrl);
  114. elseif($this->homeLink!==false)
  115. $links[]=$this->homeLink;
  116. foreach($this->links as $label=>$url)
  117. {
  118. if(is_string($label) || is_array($url))
  119. $links[]=strtr($this->activeLinkTemplate,array(
  120. '{url}'=>CHtml::normalizeUrl($url),
  121. '{label}'=>$this->encodeLabel ? CHtml::encode($label) : $label,
  122. ));
  123. else
  124. $links[]=str_replace('{label}',$this->encodeLabel ? CHtml::encode($url) : $url,$this->inactiveLinkTemplate);
  125. }
  126. echo implode($this->separator,$links);
  127. echo CHtml::closeTag($this->tagName);
  128. }
  129. }