Reputation: 2265
I have the column called query and the column called description from an index.php file generated with Gii Generator for Yii2. Both belong to the GridView widget.
I want to use the ntext
format provided by Yii2 for the query column because I need the breaks.
ntext: formats the value as an HTML-encoded plain text with newlines converted into breaks.
'columns' => [
'description:ntext',
[
'attribute' => 'query',
'format' => 'html',
'value' => function($model) {
return "<span style='font-family: Dejavu Sans, monospace'>" . $model->query . '</span>';
}
],
]
Upvotes: 1
Views: 1659
Reputation: 22164
You should use asNtext()
directly:
'columns' => [
'description:ntext',
[
'attribute' => 'query',
'format' => 'html',
'value' => function($model) {
return "<span style='font-family: Dejavu Sans, monospace'>"
. Yii::$app->formatter->asNtext($model->query) . '</span>';
}
],
]
Upvotes: 5