【问题标题】:Can't create button in cgridview in yii无法在 yii 的 cgridview 中创建按钮
【发布时间】:2023-12-20 21:59:01
【问题描述】:

以下是我的代码,但我无法在 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']
               ))
              )
               ),

    ),

    ),
     )); ?>

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

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

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

请帮助让我知道我该如何弥补

【问题讨论】:

    标签: yii-extensions yii cgridview


    【解决方案1】:

    把你的代码改成这个

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

    【讨论】:

    • 不工作 :( 解析错误:语法错误,D:\wamp\www\yii\framework\base\CComponent.php(612) 中出现意外的 '/':eval()'d 代码第 1 行
    • 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,需要 T_STRING 或 T_VARIABLE 或 T_NUM_STRING
    • 错误出在您代码中的其他地方,因为它对我非常有效。请发布您的完整代码
    • 您之前的代码显示注册按钮,但 url 无法正常工作并显示错误 Parse error: syntax error, unexpected '/' in D:\wamp\www\yii\framework\base\ CComponent.php(612) : eval()'d 代码在第 1 行
    • 这是因为您的 $_GET[] 造成了问题。保存另一个变量,然后尝试。也更新了我的代码
    【解决方案2】:

    你有错别字,改一下

     '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 来帮助您解决此类错误

    【讨论】:

    • 解析错误:语法错误,D:\wamp\www\yii\framework\base\CComponent.php(612) 中出现意外的“/”:第 1 行的 eval() 代码跨度>
    最近更新 更多