PHPackages                             terranc/yii2-observer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. terranc/yii2-observer

ActiveLibrary

terranc/yii2-observer
=====================

This is my package yii2-observer

1.3.7(6mo ago)182MITPHPPHP &gt;=5.6.0

Since Sep 12Pushed 6mo agoCompare

[ Source](https://github.com/terranc/yii2-observer)[ Packagist](https://packagist.org/packages/terranc/yii2-observer)[ Docs](https://github.com/terranc/yii2-observer)[ GitHub Sponsors](https://github.com/terranc)[ RSS](/packages/terranc-yii2-observer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (15)Used By (0)

This is my package yii2-observer
================================

[](#this-is-my-package-yii2-observer)

This is a package that allows you to write code in Yii2 using the same habits as Laravel Observer.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require terranc/yii2-observer
```

Usage
-----

[](#usage)

### Step 1

[](#step-1)

```
namespace common\models;

use yii\db\ActiveRecord;
use Terran\YiiObserver\ObserverTrait;

class User extends ActiveRecord {
    use ObserverTrait;
}
```

### Step 2

[](#step-2)

Add File: `common/observers/UserObserver.php`

```
namespace common\observers;
use common\models\User;

class UserObserver {
    public function creating(User $user) {
        // Your code ...
    }
    public function created(User $user) {
        // Your code ...
    }
    public function updating(User $user) {
        // Your code ...
    }
    public function updated(User $user) {
        // Your code ...
    }
    public function saving(User $user) {
        // Your code ...
    }
    public function saved(User $user) {
        // Your code ...
    }
    public function deleting(User $user) {
        // Your code ...
    }
    public function deleted(User $user) {
        // Your code ...
    }
}
```

### Step 3

[](#step-3)

Modify `common/config/bootstrap.php`:

```
// ...
// Add the following code as needed
\common\models\User::observe(\common\observers\UserObserver::class);
// ...
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [TerranChao](https://github.com/terranc)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance66

Regular maintenance activity

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~77 days

Total

14

Last Release

203d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7a6d99f98f7816b74eaeb19e965fc77ff2647e506e4317fa3cbe1162dc65a37?d=identicon)[terranc](/maintainers/terranc)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (113 commits)")[![mvdnbrk](https://avatars.githubusercontent.com/u/802681?v=4)](https://github.com/mvdnbrk "mvdnbrk (29 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (23 commits)")[![terranc](https://avatars.githubusercontent.com/u/224353?v=4)](https://github.com/terranc "terranc (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (14 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (13 commits)")[![pforret](https://avatars.githubusercontent.com/u/474312?v=4)](https://github.com/pforret "pforret (9 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (7 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (6 commits)")[![gregkos](https://avatars.githubusercontent.com/u/6676236?v=4)](https://github.com/gregkos "gregkos (4 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (4 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (3 commits)")[![adevade](https://avatars.githubusercontent.com/u/1066486?v=4)](https://github.com/adevade "adevade (2 commits)")[![erikn69](https://avatars.githubusercontent.com/u/4933954?v=4)](https://github.com/erikn69 "erikn69 (2 commits)")[![irfanm96](https://avatars.githubusercontent.com/u/42065936?v=4)](https://github.com/irfanm96 "irfanm96 (2 commits)")[![jamessessford](https://avatars.githubusercontent.com/u/17096446?v=4)](https://github.com/jamessessford "jamessessford (2 commits)")[![koossaayy](https://avatars.githubusercontent.com/u/6431084?v=4)](https://github.com/koossaayy "koossaayy (2 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (1 commits)")[![dietercoopman](https://avatars.githubusercontent.com/u/4672752?v=4)](https://github.com/dietercoopman "dietercoopman (1 commits)")

---

Tags

terrancyii2-observer

### Embed Badge

![Health badge](/badges/terranc-yii2-observer/health.svg)

```
[![Health](https://phpackages.com/badges/terranc-yii2-observer/health.svg)](https://phpackages.com/packages/terranc-yii2-observer)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
