ParseError syntax error, unexpected ';', expecting ']'
Re: ParseError syntax error, unexpected ';', expecting ']'
Читай всю переписку от начала и до конца. Больше нечего добавить.
Re: ParseError syntax error, unexpected ';', expecting ']'
Давай упростим задачу, без ListView и GridView
Делаем поиск в модели HistoryBalance и выводим инфу через foreach
Внутри модели HistoryBalance
Проблема решаема любыми способами. Ты хочешь два представления информации объединить в один это ListView и GridView.
Различие между ListView и GridView в том, что Grid выводит в виде таблицы, а List выводит информацию с использованием указанного представления внутри виджета.
Вот пример простого использования ListView
Пример использования GridView посмотри у kartik-v
Делаем поиск в модели HistoryBalance и выводим инфу через foreach
Код: Выделить всё
<?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);
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
?>
<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',
],
]) ?>
<?php if(!empty($model->historyBalance)) {
foreach($historyBalance as $v) { ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php }
} ?>
</div>
Код: Выделить всё
public static function findHistoryBalanceByUser($id){
return HistoryBalance::find()
->where(['user_id' => $id])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all();
}
Различие между ListView и GridView в том, что Grid выводит в виде таблицы, а List выводит информацию с использованием указанного представления внутри виджета.
Вот пример простого использования ListView
Код: Выделить всё
<?= ListView::widget([
'dataProvider' => $dataProvider,
'pager' => [
'hideOnSinglePage' => true,
'firstPageLabel' => Yii::t('main', 'First'),
'lastPageLabel' => Yii::t('main', 'Last'),
],
'itemView' => '_product_item', //вот это "с использованием указанного представления"
'layout' => '<div class="box box-solid"><div class="box-header"><div class="pull-right">{summary}</div></div></div><div class="row">{items}</div>{pager}',
])?>
Re: ParseError syntax error, unexpected ';', expecting ']'
PersonController
ошибки пишет
Код: Выделить всё
<?php
namespace backend\controllers;
use common\models\HistoryBalance;
use Yii;
use common\models\user\Person;
use backend\models\PersonSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* PersonController implements the CRUD actions for Person model.
*/
class PersonController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Person models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PersonSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
// public function actionView($id)
// {
// $model = HistoryBalance::findOne($id);
//
// return $this->render('view', [
// 'model' => $this->findModel($id),
// ]);
// }
public function actionView($id)
{
$model = $this->findModel($id)// поиск твоей модели
$searchModel = new HistoryBalance();
$dataProvider = $searchModel->search($id);
$query = HistoryBalance::find()
->where('user_id' => $id)
->orderBy('id'=> SORT_DESC)
->limit(30);
return $this->render('view', [
'model' => $model,
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}
protected function findModel($id)
{
if (($model = PersonSearch::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}
ошибки пишет
Код: Выделить всё
public function actionView($id)
{
$model = $this->findModel($id)// поиск твоей модели
$searchModel = new HistoryBalance();
$dataProvider = $searchModel->search($id);
$query = HistoryBalance::find()
->where('user_id' => $id)
->orderBy('id'=> SORT_DESC)
->limit(30);
return $this->render('view', [
'model' => $model,
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}
Re: ParseError syntax error, unexpected ';', expecting ']'
Ты прикалываешься? Пихаешь код куда попало и хочешь чтобы работало? Контроллер оставляешь какой был. А поиск добавляешь в модель HistoryBalance. Скопируй поиск в модель и скопируй страницу view. И будет тебе счастье.
Re: ParseError syntax error, unexpected ';', expecting ']'
Я не прикалываюсь. Я пытаюсь изучить на тестовом проекте.
Re: ParseError syntax error, unexpected ';', expecting ']'
какой поиск добавить в модель HistoryBalance?
Re: ParseError syntax error, unexpected ';', expecting ']'
Это добавил в модель
HistoryBalance
это добавил в вид
$HistoryBalance это подчеркивает пхп шторм, но не выводит ничего нового
HistoryBalance
Код: Выделить всё
public static function findHistoryBalanceByUser($id){
return HistoryBalance::find()
->where(['user_id' => $id])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all();
}
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\web\YiiAsset;
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;
YiiAsset::register($this);
?>
<div class="person-view">
<h1><?= Html::encode($this->title) ?></h1>
<!-- <p>-->
<!-- --><?//= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<!-- --><?//= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
// 'class' => 'btn btn-danger',
// 'data' => [
// 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
// 'method' => 'post',
// ],
// ]) ?>
<!-- </p>-->
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'user_id',
'balance',
'balance_in',
'balance_out',
'credit',
'refovod',
'rating',
'referrer:ntext',
'bonus_count',
'autoriz',
],
]) ?>
<?php if(!empty($model->HistoryBalance)) {
foreach($HistoryBalance as $v) { ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php }
} ?>
<!-- --><?//= ListView::widget([
// $dataProvider = new ActiveDataProvider([
// $query = HistoryBalance::find()
// ->where('user_id' => $id)
// ->orderBy('id'=> SORT_DESC)
// ->limit(30);
// ])
// try{echo GridView::widget([
// 'dataProvider' => $dataProvider,}catch(Exception $e){}
// }]) ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Последний раз редактировалось cqfmkapb 2019.12.23, 11:57, всего редактировалось 1 раз.
Re: ParseError syntax error, unexpected ';', expecting ']'
Посмотри внимательно вверху view, я там определил переменную, которой у тебя нет
Re: ParseError syntax error, unexpected ';', expecting ']'
Скопируй view, который я тебе дал раньше
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?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);
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
?>
<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',
],
]) ?>
<?php if(!empty($model->historyBalance)) {
foreach($historyBalance as $v) { ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php }
} ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Перепиши вот так, думаю что у тебя нет связи внутри модели Person, без проверки должно работать.
А вместо этого
можешь вывести то, что тебе нужно будет, когда заработает.
Код: Выделить всё
<?php foreach($historyBalance as $v) { ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php } ?>
Код: Выделить всё
<b><?= $v->balance ?>:</b> <?= $v->credit ?>
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?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);
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
?>
<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',
],
]) ?>
<?php foreach($historyBalance as $v) { ?>
<b><?= $v->credit ?>:</b> <?= $v->credit ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php } ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Сделай под
var_dump
Посмотреть что у тебя там выводит.
Покажи еще раз твой контроллер, модель (HistoryBalance) и view
Со всеми изменениями
Код: Выделить всё
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
Код: Выделить всё
var_dump(historyBalance);
Покажи еще раз твой контроллер, модель (HistoryBalance) и view
Со всеми изменениями
Re: ParseError syntax error, unexpected ';', expecting ']'
view
вардамп вывел
array(0) { }
Код: Выделить всё
<?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);
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
var_dump($historyBalance);
?>
<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',
],
]) ?>
<?php foreach($historyBalance as $v) { ?>
<b><?= $v->credit ?>:</b> <?= $v->credit ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php } ?>
</div>
array(0) { }
Re: ParseError syntax error, unexpected ';', expecting ']'
PersonController
HistoryBalanceController
HistoryBalanceSearch
PersonSearch
Код: Выделить всё
<?php
namespace backend\controllers;
use common\models\HistoryBalance;
use Yii;
use common\models\user\Person;
use backend\models\PersonSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* PersonController implements the CRUD actions for Person model.
*/
class PersonController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Person models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PersonSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
// public function actionView($id)
// {
// $model = $this->findModel($id)// поиск твоей модели
// $searchModel = new HistoryBalance();
// $dataProvider = $searchModel->search($id);
// $query = HistoryBalance::find()
// ->where('user_id' => $id)
// ->orderBy('id'=> SORT_DESC)
// ->limit(30);
//
// return $this->render('view', [
//
// 'model' => $model,
// 'dataProvider' => $dataProvider,
// 'searchModel' => $searchModel,
// ]);
// }
protected function findModel($id)
{
if (($model = PersonSearch::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}
Код: Выделить всё
<?php
namespace backend\controllers;
use Yii;
use common\models\HistoryBalance;
use backend\models\HistoryBalanceSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* HistoryBalanceController implements the CRUD actions for HistoryBalance model.
*/
class HistoryBalanceController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all HistoryBalance models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HistoryBalanceSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
Код: Выделить всё
<?php
namespace backend\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\HistoryBalance;
/**
* HistoryBalanceSearch represents the model behind the search form of `common\models\HistoryBalance`.
*/
class HistoryBalanceSearch extends HistoryBalance
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id', 'created_at'], 'integer'],
[['balance', 'credit', 'balance_up', 'credit_up'], 'number'],
[['type', 'comment'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = HistoryBalance::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'user_id' => $this->user_id,
'balance' => $this->balance,
'credit' => $this->credit,
'balance_up' => $this->balance_up,
'credit_up' => $this->credit_up,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['ilike', 'type', $this->type])
->andFilterWhere(['ilike', 'comment', $this->comment]);
return $dataProvider;
}
}
Код: Выделить всё
<?php
namespace backend\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\user\Person;
/**
* PersonSearch represents the model behind the search form of `common\models\user\Person`.
*/
class PersonSearch extends Person
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[[ 'id', 'user_id', 'refovod', 'bonus_count', 'autoriz'], 'integer'],
[['balance', 'balance_in', 'balance_out', 'credit', 'rating'], 'number'],
[['referrer'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Person::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'user_id' => $this->user_id,
'balance' => $this->balance,
'balance_in' => $this->balance_in,
'balance_out' => $this->balance_out,
'credit' => $this->credit,
'refovod' => $this->refovod,
'rating' => $this->rating,
'bonus_count' => $this->bonus_count,
'autoriz' => $this->autoriz,
]);
$query->andFilterWhere(['ilike', 'referrer', $this->referrer]);
return $dataProvider;
}
}
Re: ParseError syntax error, unexpected ';', expecting ']'
view
Код: Выделить всё
<?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);
$historyBalance = HistoryBalance::findHistoryBalanceByUser($model->id);
?>
<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',
],
]) ?>
<?php foreach($historyBalance as $v) { ?>
<b><?= $v->credit ?>:</b> <?= $v->credit ?>
<p><span class="glyphicon glyphicon-ok"></span> <b><?= $v->balance ?>:</b> <?= $v->credit ?></p>
<?php } ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
Я просил модель HistoryBalance, а не какие-то непонятные Search, которые тут не юзаются.
Если у тебя вывело array(0) { }
Либо не правильно поиск работает в модели, либо у тебя нет записей с БД и поэтому ничего не выводит.
Если у тебя вывело array(0) { }
Либо не правильно поиск работает в модели, либо у тебя нет записей с БД и поэтому ничего не выводит.
Re: ParseError syntax error, unexpected ';', expecting ']'
записи в таблице history_balance есть