无法在yii中的cgridview中创建按钮

时间:2013-12-28 09:34:46

标签: yii-extensions yii cgridview

以下是我的代码,但我无法在cgridview

中创建按钮
   <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
    <div class="search-form" style="display:none">
    <?php $this->renderPartial('_search',array(
'model'=>$model,
      )); ?>
    </div><!-- search-form -->

    <?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(

    'name',
    'email',





    array(
        'class'=>'CButtonColumn',
        'template'=>'{Register}{update}{view}',

        'buttons'=>array(
               'Register'=>array(
               'label'=>'Register',
               'url'=>Yii::app()->createUrl('register/create',array(
                'id'=>$_GET['id'],
               'rid'=>$_GET['rid']
               ))
              )
               ),

    ),

    ),
     )); ?>

传递给查询字符串  我收到此错误

  Parse error: syntax error, unexpected '/' in D:\wamp\www\yii\framework\base\CComponent.php(612) : eval()'d               code on line 1

出现注册按钮,但出现上述错误,但如果点击没有转到指定的网址

请帮助让我知道如何弥补

2 个答案:

答案 0 :(得分:0)

将您的代码更改为此

<?php    $id=$_GET['id'];
            $rid=$_GET['rid'];  ?>
                <?php $this->widget('zii.widgets.grid.CGridView', array(
// rest of your code

'url'=>"Yii::app()->createUrl('register/create',array(
                'id'=>$id,
               'rid'=>$rid
               ))"

更多详情

'buttonID' => array
(
    'label'=>'...',     //Text label of the button.
    'url'=>'...',       //A PHP expression for generating the URL of the button.
    'imageUrl'=>'...',  //Image URL of the button.
    'options'=>array(), //HTML options for the button tag.
    'click'=>'...',     //A JS function to be invoked when the button is clicked.
    'visible'=>'...',   //A PHP expression for determining whether the button is visible.
)

答案 1 :(得分:0)

你有一个错字,改变

 'url'=>Yii::app()->request->baseUrl.'/index.php?r=register/create&id='.$_GET['id'].'&rid='Yii::app()->user->userid))',

为:

 'url' => Yii::app()->request->baseUrl . '/index.php?r=register/create&id=' . $_GET['id'] . '&rid=' . Yii::app()->user->userid)),

使用更好的IDE来帮助您解决此类错误