Страница 5 из 8
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.25, 22:54
cqfmkapb
Код: Выделить всё
<?= GridView::widget([
'dataProvider' => new ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.25, 23:24
unknownby
А вставить в GridView все тот же $dataProvider не судьба? Который передаётся из контроллера и вывести columns какие надо
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.25, 23:28
unknownby
ElisDN писал(а): ↑2019.12.25, 22:39
Код: Выделить всё
'dataProvider' = new ActiveDataProvider([
'query' => His...
]);
У него уже есть все в контроллере, просто не может понять как взять и прописать в GridView dataProvider
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.25, 23:41
ElisDN
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 08:59
cqfmkapb
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\user\Person */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'People'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<!-- --><?//= ListView::widget([
// 'dataProvider' => $dataProvider,
// 'pager' => [
// 'hideOnSinglePage' => true,
// 'firstPageLabel' => Yii::t('main', 'First'),
// 'lastPageLabel' => Yii::t('main', 'Last'),
// ],
// 'itemView' => '_history_balance',
// 'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
// ])?>
</div>
<div class="history-balance-index">
<!--<h1>--><?//= Html::encode($this->title) ?><!--</h1>-->
<?= GridView::widget([
'dataProvider' => $dataProvider,
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
1. in /web/yii2/vendor/yiisoft/yii2/data/ActiveDataProvider.php
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 09:05
cqfmkapb
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\user\Person */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'People'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<!-- --><?//= ListView::widget([
// 'dataProvider' => $dataProvider,
// 'pager' => [
// 'hideOnSinglePage' => true,
// 'firstPageLabel' => Yii::t('main', 'First'),
// 'lastPageLabel' => Yii::t('main', 'Last'),
// ],
// 'itemView' => '_history_balance',
// 'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
// ])?>
</div>
<div class="history-balance-index">
<!--<h1>--><?//= Html::encode($this->title) ?><!--</h1>-->
<?= GridView::widget([
'dataProvider' => $dataProvider,
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
// 'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
ParseError
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ';'
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 09:39
yiijeka
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
переделать в
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30),
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 09:46
cqfmkapb
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\user\Person */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'People'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<!-- --><?//= ListView::widget([
// 'dataProvider' => $dataProvider,
// 'pager' => [
// 'hideOnSinglePage' => true,
// 'firstPageLabel' => Yii::t('main', 'First'),
// 'lastPageLabel' => Yii::t('main', 'Last'),
// ],
// 'itemView' => '_history_balance',
// 'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
// ])?>
</div>
<div class="history-balance-index">
<!--<h1>--><?//= Html::encode($this->title) ?><!--</h1>-->
<?= GridView::widget([
'dataProvider' => $dataProvider,
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
// 'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\grid\GridView::query
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 09:58
yiijeka
'dataProvider' => $dataProvider,
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
заменить на
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:00
unknownby
Ты вообще не понимаешь как это работает?
Объясняю. Пока что читай.
В контроллере у тебя передаются параметры в представление
Код: Выделить всё
public function actionView($id)
{
$model = $this->findModel($id); // поиск твоей модели
$searchModel = new HistoryBalanceSearch; //Модель поиска для твоего GridView
$dataProvider = $searchModel->search(\Yii::$app->getRequest()->get(), $id); //Тут в переменную $dataProvider передается $dataProvider из search в твоей модели HistoryBalanceSearch.
return $this->render('view', [
'model' => $model, //Передаешь модель
'dataProvider' => $dataProvider, //Передаешь dataProvider
'searchModel' => $searchModel, //Передаешь модель поиска
]);
}
Модель поиска и как у тебя там всё происходит объяснять не буду, сам понимать должен.
Дальше по твоему
actionView, когда ты открываешь файл представления
person/view
Внутри
person/view можно использовать параметры, которые ты передаешь (и не только их), а именно
$model, $dataProvider, $searchModel.
Эти три переменные приходят через контроллер.
В файле
person/view
Код: Выделить всё
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:02
unknownby
yiijeka писал(а): ↑2019.12.26, 09:58
'dataProvider' => $dataProvider,
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
заменить на
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
Зачем ему прописывать запрос внутри view, если у него возвращается $dataProvider? Если нужно будет что-то в запросе поменять, то просто в свою модель поиска зайдет и поменяет. Логика в представлении это не очень хорошо ведь, да?
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:03
yiijeka
да
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:07
unknownby
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:15
cqfmkapb
Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\user\Person */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'People'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<!-- --><?//= ListView::widget([
// 'dataProvider' => $dataProvider,
// 'pager' => [
// 'hideOnSinglePage' => true,
// 'firstPageLabel' => Yii::t('main', 'First'),
// 'lastPageLabel' => Yii::t('main', 'Last'),
// ],
// 'itemView' => '_history_balance',
// 'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
// ])?>
</div>
<div class="history-balance-index">
<!--<h1>--><?//= Html::encode($this->title) ?><!--</h1>-->
<?= GridView::widget([
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:26
unknownby
Сделай так
Код: Выделить всё
<div class="history-balance-index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:29
unknownby
Вот это логика
Код: Выделить всё
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
От которой по-хорошему нужно избавляться из представлений
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:30
cqfmkapb
у ActiveDataProvider есть, а у GridView?
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:31
cqfmkapb
Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\user\Person */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'People'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<!-- --><?//= ListView::widget([
// 'dataProvider' => $dataProvider,
// 'pager' => [
// 'hideOnSinglePage' => true,
// 'firstPageLabel' => Yii::t('main', 'First'),
// 'lastPageLabel' => Yii::t('main', 'Last'),
// ],
// 'itemView' => '_history_balance',
// 'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
// ])?>
</div>
<div class="history-balance-index">
<!--<h1>--><?//= Html::encode($this->title) ?><!--</h1>-->
<?= GridView::widget([
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'user_id',
'value' => function ($model) {
return $model->user->username;
}
],
[
'attribute' => 'balance',
'format' => 'raw',
'value' => function ($model) {
return $model->balance . '<br>
<span class="text-success">' . $model->credit . '</span>';
}
],
[
'attribute' => 'balance_up',
'format' => 'raw',
'value' => function($model) {
return \yii\helpers\Html::tag('span', $model->balance_up . '<br>' . $model->credit_up . (($model->credit_up >= 0)), [
'class' => ($model->credit_up >= 0) ? 'text-success' : 'text-danger'
]);
}
],
[
'attribute' => 'type',
'filter' => Html::activeDropDownList(
$searchModel,
'type',
HistoryBalance::getSortLabels(),
[
'everyday' => 'каждый день',
'class' =>
'form-control form-control-sm'
]
),
],
'comment',
],
]); ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:34
yiijeka
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all()]),
заменить на
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
]),
Re: ParseError syntax error, unexpected ';', expecting ']'
Добавлено: 2019.12.26, 10:41
cqfmkapb
Код: Выделить всё
public function actionView($id)
{
$model = $this->findModel($id);
$searchModel = new HistoryBalanceSearch;
$dataProvider = $searchModel->search(\Yii::$app->getRequest()->get());
$dataProvider = new ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $username])
->orderBy(['id' => SORT_DESC])
->limit(30)
]);
return $this->render('view', [
'model' => $model,
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}