Answer the question
In order to leave comments, you need to log in
How to make it display the appropriate number of records?
It turns out for me that I write one code and I get 0 entries, although I know that there are 9 entries. I have code in widget
class Counter extends Widget
{
private $params;
public function init()
{
parent::init();
$zakaz = Zakaz::find();
$this->view->params['scoreZakazAdmin'] = $zakaz->andWhere(['action' => 1])->count();
$this->view->params['scoreZakazShop'] = $zakaz->andWhere(['id_sotrud' => Yii::$app->user->id, 'action' => 1])->count();
$this->view->params['scoreDisain'] = $zakaz->andWhere(['status' => [Zakaz::STATUS_DISAIN, Zakaz::STATUS_SUC_DISAIN, Zakaz::STATUS_DECLINED_DISAIN], 'action' => 1])->count();
}
public function run()
{
return Nav::widget([
'options' => ['class' => 'nav nav-pills headerNav'],
'items' => [
['label' => 'Заказы <span class="badge pull-right">'.$this->view->params['scoreZakazAdmin'].'</span>', 'encode' => false, 'url' => ['zakaz/admin'], 'visible' => Yii::$app->user->can('seeAdmin')],
['label' => 'Заказы <span class="badge pull-right">'.$this->view->params['scoreZakazShop'].'</span>', 'encode' => false, 'url' => ['zakaz/shop'], 'visible' => Yii::$app->user->can('seeShop')],
['label' => 'Заказы <span class="badge pull-right">'.$this->view->params['scoreDisain'].'</span>', 'encode' => false, 'url' => ['zakaz/disain'], 'visible' => Yii::$app->user->can('disain')],
]
]);
}
}
Answer the question
In order to leave comments, you need to log in
$zakaz = Zakaz::find();
$zakaz->andWhere(['action' => 1])->count();
//вот тут $zakaz уже содержит результат count
//соответственно дальнейший $zakaz->andWhere должен вызывать ошибку, но у Вас они отключены.
$zakaz = Zakaz::find();
$this->view->params['scoreZakazAdmin'] = $zakaz->andWhere(['action' => 1])->count();
$zakaz = Zakaz::find();
$this->view->params['scoreZakazShop'] = $zakaz->andWhere(['id_sotrud' => Yii::$app->user->id, 'action' => 1])->count();
$zakaz = Zakaz::find();
$this->view->params['scoreDisain'] = $zakaz->andWhere(['status' => [Zakaz::STATUS_DISAIN, Zakaz::STATUS_SUC_DISAIN, Zakaz::STATUS_DECLINED_DISAIN], 'action' => 1])->count();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question