Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 97 lines (93 sloc) 3.348 kb
44bbab5 merged zii repository into yii.
qiang.xue authored
1 <?php
2 /**
3 * CLinkColumn class file.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.yiiframework.com/
4be0af6 changed copyright year.
qiang.xue authored
7 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
44bbab5 merged zii repository into yii.
qiang.xue authored
8 * @license http://www.yiiframework.com/license/
9 */
10
11 Yii::import('zii.widgets.grid.CGridColumn');
12
13 /**
14 * CLinkColumn represents a grid view column that renders a hyperlink in each of its data cells.
15 *
16 * The {@link label} and {@link url} properties determine how each hyperlink will be rendered.
17 * The {@link labelExpression}, {@link urlExpression} properties may be used instead if they are available.
18 * In addition, if {@link imageUrl} is set, an image link will be rendered.
19 *
20 * @author Qiang Xue <qiang.xue@gmail.com>
21 * @version $Id$
22 * @package zii.widgets.grid
23 * @since 1.1
24 */
25 class CLinkColumn extends CGridColumn
26 {
27 /**
28 * @var string the label to the hyperlinks in the data cells. Note that the label will not
29 * be HTML-encoded when rendering. This property is ignored if {@link labelExpression} is set.
30 * @see labelExpression
31 */
32 public $label='Link';
33 /**
34 * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
35 * as the label of the hyperlink of the data cells. In this expression, the variable
36 * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
37 * and <code>$this</code> the column object.
38 */
39 public $labelExpression;
40 /**
41 * @var string the URL to the image. If this is set, an image link will be rendered.
42 */
43 public $imageUrl;
44 /**
45 * @var string the URL of the hyperlinks in the data cells.
46 * This property is ignored if {@link urlExpression} is set.
47 * @see urlExpression
48 */
49 public $url='javascript:void(0)';
50 /**
51 * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
52 * as the URL of the hyperlink of the data cells. In this expression, the variable
53 * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
54 * and <code>$this</code> the column object.
55 */
56 public $urlExpression;
57 /**
58 * @var array the HTML options for the data cell tags.
59 */
60 public $htmlOptions=array('class'=>'link-column');
61 /**
62 * @var array the HTML options for the header cell tag.
63 */
64 public $headerHtmlOptions=array('class'=>'link-column');
65 /**
66 * @var array the HTML options for the footer cell tag.
67 */
68 public $footerHtmlOptions=array('class'=>'link-column');
69 /**
70 * @var array the HTML options for the hyperlinks
71 */
72 public $linkHtmlOptions=array();
73
74 /**
75 * Renders the data cell content.
76 * This method renders a hyperlink in the data cell.
72b9745 Updated PHPDoc @param parameter names
mdomba authored
77 * @param integer $row the row number (zero-based)
78 * @param mixed $data the data associated with the row
44bbab5 merged zii repository into yii.
qiang.xue authored
79 */
80 protected function renderDataCellContent($row,$data)
81 {
82 if($this->urlExpression!==null)
90d6aac (fixes issue 2892) reverted revision 3402 regarding issue 2824
mdomba authored
83 $url=$this->evaluateExpression($this->urlExpression,array('data'=>$data,'row'=>$row));
44bbab5 merged zii repository into yii.
qiang.xue authored
84 else
85 $url=$this->url;
86 if($this->labelExpression!==null)
90d6aac (fixes issue 2892) reverted revision 3402 regarding issue 2824
mdomba authored
87 $label=$this->evaluateExpression($this->labelExpression,array('data'=>$data,'row'=>$row));
44bbab5 merged zii repository into yii.
qiang.xue authored
88 else
89 $label=$this->label;
90 $options=$this->linkHtmlOptions;
91 if(is_string($this->imageUrl))
92 echo CHtml::link(CHtml::image($this->imageUrl,$label),$url,$options);
93 else
94 echo CHtml::link($label,$url,$options);
95 }
96 }
Something went wrong with that request. Please try again.