Yii Framework Forum: Add Column As Link In Cgridview - Yii Framework Forum

Jump to content

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

Add Column As Link In Cgridview Rate Topic: ***** 1 Votes

#1 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 231
  • Joined: 04-October 12

Posted 07 January 2013 - 09:47 AM

All I need to add link to my gridview so i wrote this code

View :

<?php
	$cmodel=new Courses;
	
	$user_id=intval($_GET['user_id']);
	
	
	
	$this->widget('zii.widgets.grid.CGridView', array(
		'id'=>'courses-grid',
		'dataProvider'=>$cmodel->searchCources($user_id),
		'filter'=>$cmodel,
		'columns'=>array(
			'course_id',
			'name_ar',
			'name_en',
			'code',
			't_time',
        	array(
            	'name'  => 't_time',
            	'value' => "CHtml::link('Add',array('packages/add','user_id'=>$user_id,'course_id'=>$data->course_id))",
            	'type'  => 'raw',
        	)
		,
	
			/*
			'req',
			'aud',
			'targets',
			'programs',
			'criterion',
			'section_id',
			'acc',
			'en',
			'ar',
			'fr',
			'image',
			*/
		
    	
	))); 
	?>



Model :

    	<?php
	...
 	
    		public function searchCources($user_id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
	
		$criteria=new CDbCriteria;
    	
    	
  	
		$criteria->compare('course_id',$this->course_id);
		$criteria->compare('name_ar',$this->name_ar,true);
		$criteria->compare('name_en',$this->name_en,true);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('t_time',$this->t_time);
		$criteria->compare('intro',$this->intro,true);
		$criteria->compare('req',$this->req,true);
		$criteria->compare('aud',$this->aud,true);
		$criteria->compare('targets',$this->targets,true);
		$criteria->compare('programs',$this->programs,true);
		$criteria->compare('criterion',$this->criterion,true);
		$criteria->compare('acc',$this->acc);
		$criteria->compare('en',$this->en);
		$criteria->compare('ar',$this->ar);
		$criteria->compare('fr',$this->fr);
		$criteria->compare('image',$this->image,true);
      	$criteria->addCondition(' course_id not in ( select course_id from ict_cpackage where user_id='.$user_id.') ');
	
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria
		));
	}
	...
	?>

But return this error :

Undefined variable: data

1- Why return this error ?
2- how to access to column value


Thanks in advance
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 07 January 2013 - 10:34 AM

Dear Friend

Let us declare the value in the following way.
Take note of double quotes and singel quotes.

array(
 'name'  => 't_time',
 'value' => 'CHtml::link("Add",array("packages/add","user_id"=>"'.$user_id.'","course_id"=>$data->course_id))',
 'type'  => 'raw',
                )



Regards.
1

#3 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 231
  • Joined: 04-October 12

Posted 07 January 2013 - 04:48 PM

thanks for your note my bro .
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