В корзине: <span id="basket-counter">5</span>
<?php Pjax::begin() ?>
<?php if (isset($basketCounter)) : ?>
<script>
$('#basket-counter').text('<?= $basketCounter ?>');
</script>
<?php endif; ?>
<!-- форма для добавления товара в корзину -->
<?php Pjax::end() ?>
public function actionAddToBasket(){
// логика добавления
return $this->render('basket-form', [
'basketCounter' => $basketCounter,
'basketSum' => // ...
]);
}
$user->password_hash = Yii::$app->security->generatePasswordHash($password, $hash);
public $old_password;
private $user;
public function __construct(User $user, $config = []){
$this->user = $user;
parent::__construct($config);
}
public function rules() {
return [
// ...
['old_password', 'validateOldPassword'],
];
}
public function validateOldPassword($attribute, $params, Validator $validator){
if (!\Yii::$app->security->validatePassword($this->{$attribute}, $this->user->password_hash)){
$this->addError($attribute, 'Старый пароль указан неверно!');
}
}
# services.yaml
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
class Status {
private $stageRepository;
public function __construct(StageRepository $stageRepository){
$this->stageRepository = $stageRepository;
}
}
class SiteControllers extends AbstractController {
public function status(Status $status) {
// ...
}
}
SELECT *
FROM messages
LEFT JOIN deleted_messages
ON messages.id = deleted_messages.message_id
WHERE
messages.chat_id = :id
AND
deleted_messages.message_id IS NULL
$config = [
'components' => [],
'modules' => [],
'on afterRequest' => function (Event $event) {
Yii::$app->response->cookie->add(new Cookie([
'name' => 'cookie_name',
'value' => 'cookie_value'
]));
}
];
$result = array_diff($arr, $findChats);
$result = array_filter($arr, function ($value) use ($findChats) {
return !in_array($value, $findChats);
});