1

我需要向我的 gridview 添加链接,此链接将使用 user_id 和 course_id 等参数调用操作。
所以我写了这段代码

看法 :

<?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',
        */


))); 
?>

模型 :

    <?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
    ));
}
...
?>

但返回此错误:

Undefined variable: data 

1-为什么返回这个错误?2-我如何访问列值

提前致谢

4

1 回答 1

2
'value' => "CHtml::link('Add',array('packages/add','user_id'=>$user_id,'course_id'=>\$data->course_id))",

您正在使用""引用您的字符串,因此您需要转义$on $data,因此它读作\$data.

于 2013-01-07T14:57:14.677 回答