Versions
Look up a class, method, property or event

CLinkColumn

Package zii.widgets.grid
Inheritance class CLinkColumn » CGridColumn » CComponent
Since 1.1
Source Code framework/zii/widgets/grid/CLinkColumn.php
CLinkColumn represents a grid view column that renders a hyperlink in each of its data cells.

The label and url properties determine how each hyperlink will be rendered. The labelExpression, urlExpression properties may be used instead if they are available. In addition, if imageUrl is set, an image link will be rendered.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
cssClassExpression string a PHP expression that is evaluated for every data cell and whose result is used as the CSS class name for the data cell. CGridColumn
filterCellContent string Returns the filter cell content. CGridColumn
filterHtmlOptions array the HTML options for the filter cell tag. CGridColumn
footerCellContent string Returns the footer cell content. CGridColumn
footerHtmlOptions array the HTML options for the footer cell tag. CLinkColumn
grid CGridView the grid view object that owns this column. CGridColumn
hasFooter boolean whether this column has a footer cell. CGridColumn
headerCellContent string Returns the header cell content. CGridColumn
headerHtmlOptions array the HTML options for the header cell tag. CLinkColumn
htmlOptions array the HTML options for the data cell tags. CLinkColumn
id string the ID of this column. CGridColumn
imageUrl string the URL to the image. CLinkColumn
label string the label to the hyperlinks in the data cells. CLinkColumn
labelExpression 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 cell. CLinkColumn
linkHtmlOptions array the HTML options for the hyperlinks CLinkColumn
url string the URL of the hyperlinks in the data cells. CLinkColumn
urlExpression 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. CLinkColumn
visible boolean whether this column is visible. CGridColumn

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CGridColumn
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getDataCellContent() Returns the data cell content. CLinkColumn
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getFilterCellContent() Returns the filter cell content. CGridColumn
getFooterCellContent() Returns the footer cell content. CGridColumn
getHasFooter() Returns whether this column has a footer cell. This is determined based on whether footer is set. CGridColumn
getHeaderCellContent() Returns the header cell content. CGridColumn
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the column. CGridColumn
raiseEvent() Raises an event. CComponent
renderDataCell() Renders a data cell. CGridColumn
renderFilterCell() Renders the filter cell. CGridColumn
renderFooterCell() Renders the footer cell. CGridColumn
renderHeaderCell() Renders the header cell. CGridColumn

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
renderDataCellContent() Renders the data cell content. CGridColumn
renderFilterCellContent() Renders the filter cell content. CGridColumn
renderFooterCellContent() Renders the footer cell content. CGridColumn
renderHeaderCellContent() Renders the header cell content. CGridColumn

Property Details

footerHtmlOptions property
public array $footerHtmlOptions;

the HTML options for the footer cell tag.

headerHtmlOptions property
public array $headerHtmlOptions;

the HTML options for the header cell tag.

htmlOptions property
public array $htmlOptions;

the HTML options for the data cell tags.

imageUrl property
public string $imageUrl;

the URL to the image. If this is set, an image link will be rendered.

label property
public string $label;

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 labelExpression is set.

See Also

labelExpression property
public string $labelExpression;

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 cell. In this expression, you can use the following variables:

  • $row the row number (zero-based).
  • $data the data model for the row.
  • $this the column object.
The PHP expression will be evaluated using evaluateExpression.

A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual.

linkHtmlOptions property
public array $linkHtmlOptions;

the HTML options for the hyperlinks

url property
public string $url;

the URL of the hyperlinks in the data cells. This property is ignored if urlExpression is set.

See Also

urlExpression property
public string $urlExpression;

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, you can use the following variables:

  • $row the row number (zero-based).
  • $data the data model for the row.
  • $this the column object.
The PHP expression will be evaluated using evaluateExpression.

A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual.

Method Details

getDataCellContent() method (available since v1.1.16)
public string getDataCellContent(integer $row)
$row integer the row number (zero-based)
{return} string the data cell content.
Source Code: framework/zii/widgets/grid/CLinkColumn.php#96 (show)
public function getDataCellContent($row)
{
    
$data=$this->grid->dataProvider->data[$row];
    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))
        return 
CHtml::link(CHtml::image($this->imageUrl,$label),$url,$options);
    else
        return 
CHtml::link($label,$url,$options);
}

Returns the data cell content. This method renders a hyperlink in the data cell.

Total 4 comments

#16817 report it
Trejder at 2014/03/31 11:36am
CLinkColumn is NOT sortable

Note, that if you use CLinkColumn to render a link, your column become not sortable! To work-around it, render link in your cells using your own function, not CLinkColumn.

So, instead of doing something like this:

array
(
    'class'=>'CLinkColumn',
    'labelExpression'=>'$data->number',
    'urlExpression'=>'"http://some-url.com/emp/".$data->number',
    'htmlOptions'=>array('style'=>'width: 70px')
),

Use column definition similar to this:

array
(
    'type'=>'raw',
    'name'=>'number',
    'value'=>'gridNumber($data)',
    'htmlOptions'=>array('style'=>'width: 70px')
),

And define gridNumber() function:

function gridNumber($model)
{
    return '<a href="http://some-url.com/emp/'.$model->number.'">'.$model->number.'</a>';
}

You will end up with pretty links in your cells, exactly the same, as in case of using CLinkColumn, but you can still sort such column.

#5560 report it
Da:Sourcerer at 2011/10/20 11:52am
RE: mailto

This might come a little late, but: Using CLinkColumn for that purpose is a bit of abuse. You can simply use email:email in your column list. See CDataColumn::type and CFormatter::formatEmail().

#2690 report it
Trejder at 2011/01/29 10:27am
PHP Expression for labelExpression or urlExpression

If you are using PHP Expression in CLinkColumn's labelExpression or urlExpression property or in any other data-related class or property remember that $data is an object only if your data provider for CGridView (or CListView), in which you use such column, is operating on object. That is true if using for example CActiveDataProvider. However, if you're using non-object data provider (for example CSqlDataProvider), $data is not an object! It is an array. Therefore you should use $data['FIELD'] in this case, instead of $data->FIELD!

Thanks to oxigen for pointing this out. More info in this forum thread.

#548 report it
Maurizio Domba Cerin at 2010/04/29 07:02am
mailto

I spent last hour to find a way to display emails in the CGridView as a mailto link using CLinkColumn...

For those trying to do that... here is the solution...

array(
    'class'=>'CLinkColumn',
    'header'=>'e-mail',
    'labelExpression'=>'$data->email',
    'urlExpression'=>'"mailto:".$data->email',
),

Leave a comment

Please to leave your comment.