ParseError syntax error, unexpected ';', expecting ']'
Re: ParseError syntax error, unexpected ';', expecting ']'
Ты основы php знаешь?
Ты сразу передавал в параметр 'model' => $this->findModel($id)
А сейчас определили переменную $model и в неё передали $this->findModel($id)
Раскомментируй строку либо передай напрямую как раньше было.
Ты сразу передавал в параметр 'model' => $this->findModel($id)
А сейчас определили переменную $model и в неё передали $this->findModel($id)
Раскомментируй строку либо передай напрямую как раньше было.
Re: ParseError syntax error, unexpected ';', expecting ']'
Ты основы php знаешь?
да
А сейчас определили переменную $model и в неё передали $this->findModel($id)
с ней ошибка возникает
да
А сейчас определили переменную $model и в неё передали $this->findModel($id)
с ней ошибка возникает
Re: ParseError syntax error, unexpected ';', expecting ']'
Ну так верни как было,
Передай напрямую
'model' => $this->findModel($id)
А то ты закомментировал строку и в переменной $model теперь нет модели, а null
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?php
namespace backend\controllers;
use backend\models\HistoryBalanceSearch;
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,
// ]);
// }
public function actionView($id)
{
$model = $this->findModel($id)// поиск твоей модели
$searchModel = new HistoryBalanceSearch;
$dataProvider = $searchModel->search(\Yii::$app->getRequest()->get(), $id);
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.'));
}
}
$model = $this->findModel($id)// поиск твоей модели
как тогда быть?
Re: ParseError syntax error, unexpected ';', expecting ']'
Поставить точку с запятой в конце.
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?php
namespace backend\controllers;
use backend\models\HistoryBalanceSearch;
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,
// ]);
// }
public function actionView($id)
{
$model = $this->findModel($id);
$searchModel = new HistoryBalanceSearch;
$dataProvider = $searchModel->search(\Yii::$app->getRequest()->get(), $id, );
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.'));
}
}
Re: ParseError syntax error, unexpected ';', expecting ']'
Call to a member function formName() on null
Error
Call to a member function formName() on null
1. in /web/yii2/vendor/yiisoft/yii2/helpers/BaseHtml.php at line 2276
Error
Call to a member function formName() on null
1. in /web/yii2/vendor/yiisoft/yii2/helpers/BaseHtml.php at line 2276
Код: Выделить всё
<?php
use common\models\HistoryBalance;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\HistoryBalanceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'History Balances');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="history-balance-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('app', 'Create History Balance'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= \yii\widgets\DetailView::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',
],
]); ?>
<!---->
<!-- --><?//= \yii\widgets\ListView::widget([
// 'model' => $model,
// 'attributes' => [
// 'id',
// 'user_id',
// 'balance',
// 'credit',
// 'balance_up',
// 'credit_up',
// 'type',
// 'comment',
// 'created_at',
// ],
// ]) ?>
</div>
Re: ParseError syntax error, unexpected ';', expecting ']'
выводит только виды всех юзеров, а мне нужно вынести только одного юзера
Re: ParseError syntax error, unexpected ';', expecting ']'
Погугли как использовать ListView, в самом начале я давал ссылку и все рассказывал. Прочитай ещё раз переписку.
Ты должен понять, что всю работу сделать должен ты, а люди на форуме тебе только подсказывают куда двигаться, в каком направлении.
Ты должен понять, что всю работу сделать должен ты, а люди на форуме тебе только подсказывают куда двигаться, в каком направлении.
Re: ParseError syntax error, unexpected ';', expecting ']'
виды могу вывести, вот они не нужны.
Нужно как в индексном файле
Нужно как в индексном файле
Re: ParseError syntax error, unexpected ';', expecting ']'
он выводит всех пользователей только
Re: ParseError syntax error, unexpected ';', expecting ']'
получилось вывести данные с другой таблицы, но только выводит всех записи всех пользователей, а нужно конкретного. как такое сделать?
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
->andWhere(['user_id' => $userId])
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
'dataProvider' => HistoryBalance::find()
->andWhere(['user_id' => $id])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
Call to a member function getCount() on array
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
in /web/yii2/vendor/yiisoft/yii2/widgets/BaseListView.php at line 190
181182183184185186187188189190191192193194195196197198199
$tag = ArrayHelper::remove($options, 'tag', 'div');
return Html::tag($tag, $this->emptyText, $options);
}
/**
* Renders the summary text.
*/
public function renderSummary()
{
$count = $this->dataProvider->getCount();
if ($count <= 0) {
return '';
}
$summaryOptions = $this->summaryOptions;
$tag = ArrayHelper::remove($summaryOptions, 'tag', 'div');
if (($pagination = $this->dataProvider->getPagination()) !== false) {
$totalCount = $this->dataProvider->getTotalCount();
$begin = $pagination->getPage() * $pagination->pageSize + 1;
$end = $begin + $count - 1;
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
'dataProvider' = new ActiveDataProvider([
'query' => His...
]);
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
'dataProvider' = new ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $id])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
phpshtorm подчеркивает
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?= GridView::widget([
'dataProvider' = new ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $id])
->orderBy(['id' => SORT_DESC])
->limit(30)
->all(),
]),
Re: ParseError syntax error, unexpected ';', expecting ']'
ParseError
syntax error, unexpected '=', expecting ']'
syntax error, unexpected '=', expecting ']'
Re: ParseError syntax error, unexpected ';', expecting ']'
Код: Выделить всё
<?= GridView::widget([
'dataProvider' => new ActiveDataProvider([
'query' => HistoryBalance::find()
->andWhere(['user_id' => $id])
->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.