Yii Framework Forum: Cgridview Insert Dynamic Chhtml::link Into Column - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview Insert Dynamic Chhtml::link Into Column Rate Topic: -----

#1 User is offline   hugmungus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 30-January 14

Posted 24 April 2014 - 11:18 AM

Hello everybody,

I'm looking to insert a CHtml::link into a column on my CGridview. The catch is I want to build the CHtml::link string and return it from a function as I'd also like to have some rows with a plain string, like so:

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'organizations-grid',
    'dataProvider'=>$model->search(),
    'columns'=>array(
        'title',
        array(
            'header'=>'Students',
            'type'=>'raw',
            'value'=>'getNumStudents($data)',
        ),
    ),
));

function getNumStudents($data) {
	$output=Yii::app()->db->createCommand($sql)->query()->readAll();
	
	if($output[0]["count"] == 0) {
		return "No students added";
	} else {
		return 'CHtml::link("View '.$output[0]["count"].' students", array("/organizations/getStudents"), array("students"=>"'.$output.'"))';
	}
}


However, when this runs, it just prints the return value as a string instead of a link; CHtml::link prefix and all. Thanks in advance for the help, I could really use it!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users