Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何编写yii2 contentOptions使其具有功能和样式?_Php_Yii2 - Fatal编程技术网

Php 如何编写yii2 contentOptions使其具有功能和样式?

Php 如何编写yii2 contentOptions使其具有功能和样式?,php,yii2,Php,Yii2,我的GridView中有我的contentOptions,它具有以下功能。但除此之外,我希望文本对齐-居中。我该怎么做 这是我的内容选项 'contentOptions' => function (Service $model) { $services = Service::getServices($model->services); if (BaseStringHelper::countWords($services) < 5) { retur

我的GridView中有我的
contentOptions
,它具有以下功能。但除此之外,我希望文本对齐-居中。我该怎么做

这是我的内容选项

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

您可以为此使用引导类:

return ['title' => $allPurposes, 'class' => 'text-center'];
或者,如果您不使用引导,您可以使用纯CSS:

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

您可以使用Bootstrap的类执行以下操作:

return ['title' => $allPurposes, 'class' => 'text-center'];
或者,如果您不使用引导,您可以使用纯CSS:

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

对于行选项:

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

对于行选项:

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


谢谢你能告诉我在没有回报的地方怎么做吗?我已经更新了我的代码。我还需要对
value
执行此操作。基本上是一样的-只需类-
返回['class'=>'text center']不知怎的我出错了。我已经更新了我的答案如何将其写入
value
它应该写入contentOptions而不是value。@MKD还有
rowOptions
,谢谢。你能告诉我在没有回报的地方怎么做吗?我已经更新了我的代码。我还需要对
value
执行此操作。基本上是一样的-只需类-
返回['class'=>'text center']不知怎的我出错了。我已经更新了我的答案如何将其写入
value
它应该写入contentOptions而不是value。@MKD也有
rowOptions
用于此。我已将您的rowOptions替换为我的,但这也不起作用。它说我正在设置未知属性你能显示完整的gridview代码吗。。rowOptions是gridview属性。我假设您正在将其添加到列数组中。我没有看到任何Gridview文本或列数组?也许您可以将我们的讨论移动到聊天吗?:(我已将您的rowOptions替换为我的,但这也不起作用。它表示我正在设置未知属性您可以显示完整的gridview代码..rowOptions是gridview属性。我假设您正在将其添加到columns数组中。我看不到任何gridview文本或columns数组?或许您可以将我们的讨论转移到chat吗?:(