Yii / CDetailView: Customizar

51 views
Skip to first unread message

Ricardo

unread,
Sep 6, 2013, 8:30:44 PM9/6/13
to yii-framew...@googlegroups.com
Olá,

Gostaria de saber como faço no CDetailView o que eu consegui fazer no CGridView.
Vou postar meu CGridView:

    $this->widget('zii.widgets.grid.CGridView', array(
    ..
        'columns'=>array(
            array("name" => "id",   'value' => '$data->id', 'htmlOptions'=>array('width'=>'70px')),
            array("name" => "name", 'type'=>'raw', 'value' => function($data){
                if($data->active) return $data->name;
                else return "$data->name <span class='noActive'>(desativado)</span>";
               
            }),

            ..
        ),
    ));


Porém ao fazer o mesmo.. 'value' => function no CDetailView:

$this->widget('zii.widgets.CDetailView', array(
    'htmlOptions' =>  array('class' => 'table cdetailview table-bordered' ),
    'data'=>$model,
    'attributes'=>array(
        'id',
        'name',
        array("name" => "name", 'type'=>'raw', 'value' => function($options,$templateData){
            return "qualquer coisa..";
        }),

    ),
));


Apresenta o seguinte erro:

protected function renderItem($options,$templateData)
 {
         echo strtr(isset($options['template']) ? $options['template'] : $this->itemTemplate,$templateData);
 }


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enfim, alguém sabe como colocar uma function na value? para o widget CDetailView
Tentei achar na net, mas não consegui..

Ricardo

unread,
Sep 6, 2013, 9:01:53 PM9/6/13
to yii-framew...@googlegroups.com
Solução que eu acabei de conseguir, foi colocar a função para fora..
Exemplo:

<?php
function viewOriginal(){
    return "<a href='#'>Ver Original</a>";
}


$this->widget('zii.widgets.CDetailView', array(
    ..
    'attributes'=>array(
        ..
        array("name" => "language", "type" => "raw", "value" => viewOriginal()),
        ..
    ),
)); ?>

Ricardo

unread,
Sep 6, 2013, 9:08:16 PM9/6/13
to yii-framew...@googlegroups.com
Porém para acessar o model.. alterei:

- function viewOriginal($model){ .. }
- array("name" => "language", "type" => "raw", "value" => viewOriginal($model)),

Reply all
Reply to author
Forward
0 new messages