I've used this piece of code now qiang
<?php
class MySort extends CSort
{
public function sortLink($attribute, $label=NULL, $htmlOptions=array())
{
if(array_key_exists($attribute, $this->attributes))
return $this->link($attribute, $label, $htmlOptions);
else
return $this->link($attribute, $label, array_merge(array('class'=>'nolink')), $htmlOptions);
}
}
?>
I've set 'attributes' in my controller
<?php
$sort=new CSort('Bundle');
$sort->attributes=array(
'bundle.id'=>'Id',
'bundle.quantityOnHand'=>'QOH',
'bundle.sizeId'=>'Size',
'bundle.lengthId'=>'Length',
'bundle.bundlePrice'=>'Price',
'bundle.totalPrice'=>'Total Value',
'bundle.createTime'=>'Created'
);
$sort->applyOrder($criteria);
?>
and finally in my view
<tr>
<th><?php echo MySort::sortLink('bundle.id'); ?></th>
<th><?php echo $sort->link('bundle.quantityOnHand'); ?></th>
<th><?php echo $sort->link('bundle.sizeId'); ?></th>
<th><?php echo $sort->link('bundle.lengthId'); ?></th>
<th><?php echo $sort->link('bundle.bundlePrice'); ?></th>
<th><?php echo $sort->link('bundle.totalPrice'); ?></th>
<th><?php echo $sort->link('bundle.createTime'); ?></th>
<th>Actions</th>
</tr>
The bundle.id passed to MySort::sortLink() function raises the following exception
Description
Property "BundleController.attributes" is not defined.
Source File
C:Apache2.2htdocsprojectprotectedcomponentsMySort.php(7)
00001: <?php
00002:
00003: class MySort extends CSort
00004: {
00005: public function sortLink($attribute, $label=NULL, $htmlOptions=array())
00006: {
00007: if(array_key_exists($attribute, $this->attributes))
00008: return $this->link($attribute, $label, $htmlOptions);
00009: else
00010: return $this->link($attribute, $label, array_merge(array('class'=>'nolink')), $htmlOptions);
00011: }
00012: }
00013:
00014: ?>
Stack Trace
#0 C:Apache2.2htdocsprojectprotectedcomponentsMySort.php(7): CComponent->__get('attributes')
#1 C:Apache2.2htdocsprojectprotectedviewsbundlelist.php(10): MySort->sortLink('bundle.id')
#2 C:Apache2.2yii_1.0.4frameworkwebCBaseController.php(119): require('C:Apache2.2ht...')
#3 C:Apache2.2yii_1.0.4frameworkwebCBaseController.php(88): CBaseController->renderInternal('C:Apache2.2ht...', Array, true)
#4 C:Apache2.2yii_1.0.4frameworkwebCController.php(681): CBaseController->renderFile('C:Apache2.2ht...', Array, true)
#5 C:Apache2.2yii_1.0.4frameworkwebCController.php(620): CController->renderPartial('list', Array, true)
#6 C:Apache2.2htdocsprojectprotectedcontrollersBundleController.php(174): CController->render('list', Array)
#7 C:Apache2.2yii_1.0.4frameworkwebactionsCInlineAction.php(32): BundleController->actionList()
#8 C:Apache2.2yii_1.0.4frameworkwebCController.php(279): CInlineAction->run()
#9 C:Apache2.2yii_1.0.4frameworkwebCController.php(257): CController->runAction(Object(CInlineAction))
#10 C:Apache2.2yii_1.0.4frameworkwebCController.php(236): CController->runActionWithFilters(Object(CInlineAction), NULL)
#11 C:Apache2.2yii_1.0.4frameworkwebCWebApplication.php(332): CController->run('list')
#12 C:Apache2.2yii_1.0.4frameworkwebCWebApplication.php(120): CWebApplication->runController('bundle/list')
#13 C:Apache2.2yii_1.0.4frameworkbaseCApplication.php(133): CWebApplication->processRequest()
#14 C:Apache2.2htdocsprojectindex.php(11): CApplication->run()
#15 {main}