如何编写yii2 contentOptions以具有功能和风格?

I have my contentOptions in my GridView, which has the function. But besides that, I want the text to be text-aligned - center. How should I do that?

Here's my content options

'contentOptions' => function (Service $model) {
    $services = Service::getServices($model->services);
    if (BaseStringHelper::countWords($services) < 5) {
        return $services;
    }
    return null;
}

You can use Bootstrap's class for this:

return ['title' => $allPurposes, 'class' => 'text-center'];

or if you are not using Bootstrap you can use pure CSS:

return ['title' => $allPurposes, 'style' => 'text-align:center'];

Try:

'contentOptions' => function (Client $model) {
    $allPurposes = ClientController::getClientIncomeSourceTitles($model->incomeSourceIdArray);
    if (BaseStringHelper::countWords($allPurposes) > 2) {
        return ['title' => $allPurposes, 'style' => 'text-align:center'];
    }
    return null;
}

For rowOptions:

'rowOptions' => function ($model, $index, $widget, $grid){
      return [ 'style'=>'text-align: center;' ];
    },