Snippets Collections
//para cualquier campo usar:
'headerOptions' => ['style' => 'text-align:center;'],
'contentOptions' => ['style' => 'text-align:center; width:2%; vertical-align:middle;'],
//para casos donde el campo venga del modelo 
$columns[] = [
        'attribute' => 'nombre_proyecto',
        'label' => 'Nombre del Proyecto',
        'headerOptions' => ['style' => 'text-align:center; width:10%;text-color:white;'],
        'contentOptions' => ['style' => 'text-align:center; vertical-align:middle;'],
        'value' => function ($data) {
            // Encoded to avoid XSS, then insert line breaks cada 40 caracteres
            $name = Html::encode($data->nombre_proyecto);
            return nl2br(wordwrap($name, 40, "\n", true));
        },
        'format' => 'raw',
    ];
 // para casos donde se use la funcion listar
 'id_indicador' => [
        'attribute' => 'id_indicador',
        'label' => 'Indicador',
        'headerOptions' => ['style' => 'text-align:center;'],
        'contentOptions' => ['style' => 'text-align:center; width:2%; vertical-align:middle;'],
        'filter' => app\models\Indicadores::listAcuatico(),
        'value' => function ($data) {
            $s = app\models\Indicadores::find()->where(['id_indicador' => $data->id_indicador])->one();
            if (!$s) {
                return '';
            }
            // Encoded to avoid XSS, then insert line breaks cada 20 caracteres
            $name = Html::encode($s->nombre_indicador);
            return nl2br(wordwrap($name, 40, "\n", true));
        },
        'format' => 'raw',
    ],
   
   
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
star

Mon Oct 13 2025 15:14:35 GMT+0000 (Coordinated Universal Time)

#yii2
star

Thu Feb 17 2022 19:32:53 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/41675051/get-response-in-json-format-in-yii2

#php #yii2 #response #json #format

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension