GridView

Boa tarde pessoal, sou novo no Yii e estou com uma dúvida sobre como mudar o nome na minha View, segue a imagem e a regra.

<?= GridView::widget([

    'dataProvider' =&gt; &#036;dataProvider,


    'filterModel' =&gt; &#036;searchModel,


    'columns' =&gt; [


        ['class' =&gt; 'yii&#092;grid&#092;SerialColumn'],





        'product_unit',


        'product_name',


        'quantity',


        [color=&quot;#FF0000&quot;]'gross_total',


        'gross_total',[/color]


        ['class' =&gt; 'yii&#092;grid&#092;ActionColumn'],


    ],





]); ?&gt;

Onde (gross_total) = Entradas e o outro (gross_total) = Saídas.

Como posso resolver isso?

Sua model possuí um método chamado attributeLabels.

Lá vc pode definir as labels do seus atributos.

Este, mas eu coloquei dois (gross_total) em minha view, como eu posso renomear um como Entradas e o outro como Saídas?

public function attributeLabels()

{


    return [


        'id' =&gt; 'ID',


        'product_name' =&gt; 'Produtos',


        'quantity' =&gt; 'Quantidade Vendida',


        'gross_total' =&gt; 'Total',


    ];


}

Olá,

Basta fazer assim:




<?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],


            'product_unit',

            'product_name',

            'quantity',

            [

         		'attribute' => 'gross_total',

         		'label' => 'Entrada'

        	],

        	[

     			'attribute' => 'gross_total',

         		'label' => 'Saída',

        	],

 	       ['class' => 'yii\grid\ActionColumn'],

        ],


    ]); ?>




Se você precisa mudar o valor para cada coluna faça assim:




echo GridView::widget([

 	'dataProvider' => $dataProvider,

 	'columns' => [

 		['class' => 'yii\grid\SerialColumn'],

 		'id',

 		'nome',

 		[

 			'value' => function ($data) {

     			return strtolower($data->nome); // Pode retornar o valor que vc quiser aqui.

 			},

 		],

 	], 

]);



Perfeito Jacques, funcionou aqui, obrigado pela ajuda.