@@ -321,7 +321,7 @@ class AccessOnce extends Behavior
321
321
{
322
322
$owner = $this->owner;
323
323
324
- if ($owner instanceof Controller) {
324
+ if ($owner instanceof \yii\web\ Controller) {
325
325
return [
326
326
$owner::EVENT_BEFORE_ACTION => 'имя_обработчика',
327
327
$owner::EVENT_AFTER_ACTION => 'имя_обработчика',
@@ -337,7 +337,7 @@ class AccessOnce extends Behavior
337
337
EVENT_BEFORE_ACTION и EVENT_AFTER_ACTION у этих объектов может и не быть. Поэтому вводим дополнительную проверку
338
338
339
339
``` php
340
- if ($owner instanceof Controller) {
340
+ if ($owner instanceof \yii\web\ Controller) {
341
341
```
342
342
343
343
которая ограничит неверное использование поведения AccessOnce.
@@ -414,7 +414,7 @@ class AccessOnce extends Behavior
414
414
{
415
415
if (in_array($event->action->id, $this->actions, true)) {
416
416
if (\Yii::$app->session->get($event->action->id . '-access-lock') !== null) {
417
- throw new HttpException(403, $this->message);
417
+ throw new \yii\web\ HttpException(403, $this->message);
418
418
}
419
419
}
420
420
}
@@ -424,15 +424,15 @@ class AccessOnce extends Behavior
424
424
При срабатывании
425
425
426
426
``` php
427
- throw new HttpException(403, $this->message);
427
+ throw new \yii\web\ HttpException(403, $this->message);
428
428
```
429
429
430
430
пользователя перекинет на ` /index.php?r=site/error ` . Самостоятельно попробуйте разобраться как сработает ` site/error ` .
431
431
432
432
После всего сделанного, в итоге имеем:
433
433
434
434
``` php
435
- class SiteController extends Controller
435
+ class SiteController extends \yii\web\ Controller
436
436
{
437
437
public function behaviors()
438
438
{
@@ -454,7 +454,7 @@ class AccessOnce extends Behavior
454
454
{
455
455
$owner = $this->owner;
456
456
457
- if ($owner instanceof Controller) {
457
+ if ($owner instanceof \yii\web\ Controller) {
458
458
return [
459
459
$owner::EVENT_BEFORE_ACTION => 'checkAccess',
460
460
$owner::EVENT_AFTER_ACTION => 'closeDoor',
0 commit comments