Blame view

common/components/IpBehavior.php 650 Bytes
950817c6   Alex Savenko   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  <?php
      /**
       * Created by PhpStorm.
       * User: yarik
       * Date: 20.06.17
       * Time: 12:41
       */
      
      namespace common\components;
      
      use yii\base\Behavior;
      use yii\db\ActiveRecord;
      
      class IpBehavior extends Behavior
      {
          public function events()
          {
              return [
                  ActiveRecord::EVENT_BEFORE_INSERT => 'writeIp',
              ];
          }
          
          public function writeIp()
          {
              /**
               * @var \frontend\models\Order $owner
               */
              $owner = $this->owner;
              $owner->ip = \Yii::$app->request->userIP;
          }
      }