~fusonic/chive/1.1

« back to all changes in this revision

Viewing changes to yii/zii/widgets/CBreadcrumbs.php

  • Committer: Matthias Burtscher
  • Date: 2010-02-12 09:12:35 UTC
  • Revision ID: matthias.burtscher@fusonic.net-20100212091235-jqxrb62klx872ajc
* Updated Yii to 1.1.0
* Removed CodePress and CodeMirror
* Updated jQuery and some plugins
* Cleaned some code ...

Show diffs side-by-side

added added

removed removed

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