How to get the value of the user ID in Cgridview - Yii

Asked

Viewed 379 times

0

In place of {{ VALOR DO ID }} I’d like to put the ID of the respective user. Seeing that this is a Row of a Grid.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'usuario-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'idUsuario',
        'nome',
        'email',
        array(
            'class'=>'CButtonColumn',
            'template'=>'{view}{update}{delete}',
            'buttons'=>array (
                'view' => array (
                    'options'=> array (
                            'data-url' => Yii::app()->controller->createUrl("view", array("id" => {{ VALOR DO ID }} )),
                    ),
                    'click'=>'function(){
                                   $(".content").load($(this).data("url"));
                              }',
                    'url'=>'"#"',
                ),
            ),
        ),
    ),
)); ?>

3 answers

2

I bypassed the situation in this way. However, I do not consider the question answered.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'usuario-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'idUsuario',
        'nome',
        'email',
        array(
            'class'=>'CButtonColumn',
            'template'=>'{view}{update}{delete}',
            'buttons'=>array (
                'view' => array (
                    'click'=>'function(e){
                                   e.preventDefault();
                                   $(".content").load($(this).attr("href"));
                              }',
                    'url'=>'Yii::app()->controller->createUrl("myAction",array("id"=>$data->primaryKey))'
                ),
            ),
        ),
    ),
)); ?>
  • If you have PHP 5.3, you can use a function as follows: 'url' => Function($data) { Return ...; }

0

'url' => 'Yii::app()->controller->createUrl("view", array("id"=>$data->idUsuario))'

-1

Try:

'data-url' => Yii::app()->controller->createUrl("view", array("id" => '$data->idUsuario' )),
  • everything I put in quotes he considers as literal. That is: <div data-url="$data->idUsuario"></div>. of course the special characters are represented differently, but that’s basically what happens.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.