PHP code example of indifferend / yii2-behaviors

1. Go to this page and download the library: Download indifferend/yii2-behaviors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

indifferend / yii2-behaviors example snippets


    public function behaviors()
    {
        return [
            'purify' => [
                'class' => PurifyBehavior::className(),
                'attributes' => ['title', 'content'],
                'config' => [
                    'AutoFormat.Linkify' => true,
                    'HTML.TargetBlank' => true,
                    'HTML.Nofollow' => true
                ]
            ]
        ];
    }

    public function behaviors()
    {
            return [
                'carbon' => [
                    'class' => CarbonBehavior::className(),
                    'attributes' => [
                        'createdAt',
                        'trialEndAt',
                    ]
                ],
            ];
     }

      $user = UserModel::findOne(1);

      var_dump($user->createdAt->year); // 2016
      var_dump($user->createdAt->month); // 5
      var_dump($user->createdAt->day); // 10

      // change date
      
      $user->trialEndAt->addYear();
      $user->save();


php composer.phar