Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 96 lines (93 sloc) 3.348 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
<?php
/**
* CLinkColumn class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

Yii::import('zii.widgets.grid.CGridColumn');

/**
* CLinkColumn represents a grid view column that renders a hyperlink in each of its data cells.
*
* The {@link label} and {@link url} properties determine how each hyperlink will be rendered.
* The {@link labelExpression}, {@link urlExpression} properties may be used instead if they are available.
* In addition, if {@link imageUrl} is set, an image link will be rendered.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package zii.widgets.grid
* @since 1.1
*/
class CLinkColumn extends CGridColumn
{
/**
* @var string the label to the hyperlinks in the data cells. Note that the label will not
* be HTML-encoded when rendering. This property is ignored if {@link labelExpression} is set.
* @see labelExpression
*/
public $label='Link';
/**
* @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
* as the label of the hyperlink of the data cells. In this expression, the variable
* <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
* and <code>$this</code> the column object.
*/
public $labelExpression;
/**
* @var string the URL to the image. If this is set, an image link will be rendered.
*/
public $imageUrl;
/**
* @var string the URL of the hyperlinks in the data cells.
* This property is ignored if {@link urlExpression} is set.
* @see urlExpression
*/
public $url='javascript:void(0)';
/**
* @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
* as the URL of the hyperlink of the data cells. In this expression, the variable
* <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
* and <code>$this</code> the column object.
*/
public $urlExpression;
/**
* @var array the HTML options for the data cell tags.
*/
public $htmlOptions=array('class'=>'link-column');
/**
* @var array the HTML options for the header cell tag.
*/
public $headerHtmlOptions=array('class'=>'link-column');
/**
* @var array the HTML options for the footer cell tag.
*/
public $footerHtmlOptions=array('class'=>'link-column');
/**
* @var array the HTML options for the hyperlinks
*/
public $linkHtmlOptions=array();

/**
* Renders the data cell content.
* This method renders a hyperlink in the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row,$data)
{
if($this->urlExpression!==null)
$url=$this->evaluateExpression($this->urlExpression,array('data'=>$data,'row'=>$row));
else
$url=$this->url;
if($this->labelExpression!==null)
$label=$this->evaluateExpression($this->labelExpression,array('data'=>$data,'row'=>$row));
else
$label=$this->label;
$options=$this->linkHtmlOptions;
if(is_string($this->imageUrl))
echo CHtml::link(CHtml::image($this->imageUrl,$label),$url,$options);
else
echo CHtml::link($label,$url,$options);
}
}
Something went wrong with that request. Please try again.