gpt4 book ai didi

grid - Yii2 GridView 安装。无法定位类别 'kvgrid' 的消息源

转载 作者:行者123 更新时间:2023-12-04 03:02:11 25 4
gpt4 key购买 nike

我已经从 here 下载了 yii2-grid-master

根据 readme.md
我已经在我的控制台中安装了 composer 和 din:

php composer.phar require kartik-v/yii2-grid "@dev"

现在我尝试根据文档使用它。我把这个放在我的观点中:
use kartik\grid\GridView;
$gridColumns = [
['class' => 'kartik\grid\SerialColumn'],
[
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'name',
'pageSummary' => 'Page Total',
'vAlign'=>'middle',
'headerOptions'=>['class'=>'kv-sticky-column'],
'contentOptions'=>['class'=>'kv-sticky-column'],
'editableOptions'=>['header'=>'Name', 'size'=>'md']
],
[
'attribute'=>'color',
'value'=>function ($model, $key, $index, $widget) {
return "<span class='badge' style='background-color: {$model->color}'> </span> <code>" .
$model->color . '</code>';
},
'filterType'=>GridView::FILTER_COLOR,
'vAlign'=>'middle',
'format'=>'raw',
'width'=>'150px',
'noWrap'=>true
],
[
'class'=>'kartik\grid\BooleanColumn',
'attribute'=>'status',
'vAlign'=>'middle',
],
[
'class' => 'kartik\grid\ActionColumn',
'dropdown' => true,
'vAlign'=>'middle',
'urlCreator' => function($action, $model, $key, $index) { return '#'; },
'viewOptions'=>['title'=>$viewMsg, 'data-toggle'=>'tooltip'],
'updateOptions'=>['title'=>$updateMsg, 'data-toggle'=>'tooltip'],
'deleteOptions'=>['title'=>$deleteMsg, 'data-toggle'=>'tooltip'],
],
['class' => 'kartik\grid\CheckboxColumn']
];
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false
'beforeHeader'=>[
[
'columns'=>[
['content'=>'Header Before 1', 'options'=>['colspan'=>4, 'class'=>'text-center warning']],
['content'=>'Header Before 2', 'options'=>['colspan'=>4, 'class'=>'text-center warning']],
['content'=>'Header Before 3', 'options'=>['colspan'=>3, 'class'=>'text-center warning']],
],
'options'=>['class'=>'skip-export'] // remove this row from export
]
],
'toolbar' => [
['content'=>
Html::button('&lt;i class="glyphicon glyphicon-plus">&lt;/i>', ['type'=>'button', 'title'=>Yii::t('kvgrid', 'Add Book'), 'class'=>'btn btn-success', 'onclick'=>'alert("This will launch the book creation form.\n\nDisabled for this demo!");']) . ' '.
Html::a('&lt;i class="glyphicon glyphicon-repeat">&lt;/i>', ['grid-demo'], ['data-pjax'=>0, 'class' => 'btn btn-default', 'title'=>Yii::t('kvgrid', 'Reset Grid')])
],
'{export}',
'{toggleData}'
],
'pjax' => true,
'bordered' => true,
'striped' => false,
'condensed' => false,
'responsive' => true,
'hover' => true,
'floatHeader' => true,
'floatHeaderOptions' => ['scrollingTop' => $scrollingTop],
'showPageSummary' => true,
'panel' => [
'type' => GridView::TYPE_PRIMARY
],
]);

当我去那里时,我收到以下错误:
Unable to locate message source for category 'kvgrid'.

怎么了?另外,我没有上传任何来源,因为我不知道应该把它放在哪里,而且它没有写在自述文件中=)此外,在框架目录(供应商)中,我找到了一些 kartik-v 目录并试图更改kartik 到 kartik-v 仍然没有合适的结果。需要一些帮助。

UPD1
我已将工具栏更改为:
'toolbar' =>  [
['content'=>
Html::button('&lt;i class="glyphicon glyphicon-plus">&lt;/i>', ['type'=>'button', 'title'=>Yii::t('app', 'Add Book'), 'class'=>'btn btn-success', 'onclick'=>'alert("This will launch the book creation form.\n\nDisabled for this demo!");']) . ' '.
Html::a('&lt;i class="glyphicon glyphicon-repeat">&lt;/i>', ['grid-demo'], ['data-pjax'=>0, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')])
],
'{export}',
'{toggleData}'
],

Insane Scull 提出建议,我收到:
The 'gridview' module MUST be setup in your Yii configuration file and must be an instance of 'kartik\grid\Module'.

我尝试添加到 /basic/config/web.php到关联数组 $config一个元素:
/*'i18n' => [
'translations' => [
'app' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
],
'kvgrid' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
],
]
],

但不幸的是我收到:
Setting read-only property: yii\web\Application::i18n error on the whole site.

怎么了?

最佳答案

我想你是在使用国际化或者说翻译功能Yii::t()没有消息类别 kvgrid .

中创建消息类别配置或使用默认类别 app .

'components' => [
.
.
.
'i18n' => [
'translations' => [
'app' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
],
'kvgrid' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
],
.
.
.
],

试试这个方法:
'toolbar' =>  [
['content'=>
Html::button('&lt;i class="glyphicon glyphicon-plus">&lt;/i>', ['type'=>'button', 'title'=>Yii::t('app', 'Add Book'), 'class'=>'btn btn-success', 'onclick'=>'alert("This will launch the book creation form.\n\nDisabled for this demo!");']) . ' '.
Html::a('&lt;i class="glyphicon glyphicon-repeat">&lt;/i>', ['grid-demo'], ['data-pjax'=>0, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')])
],

关于grid - Yii2 GridView 安装。无法定位类别 'kvgrid' 的消息源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36232755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com