PHPackages                             synatree/yii2-readonly-behavior - 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. [Database &amp; ORM](/categories/database)
4. /
5. synatree/yii2-readonly-behavior

ActiveYii2-extension[Database &amp; ORM](/categories/database)

synatree/yii2-readonly-behavior
===============================

This behavior class allows you to specify an attribute which, upon setting or being set, prevents the model from being changed. Think of it as a latch that locks the model once a particular value has been set and saved.

12302[2 issues](https://github.com/synatree/yii2-readonly-behavior/issues)PHP

Since Feb 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/synatree/yii2-readonly-behavior)[ Packagist](https://packagist.org/packages/synatree/yii2-readonly-behavior)[ RSS](/packages/synatree-yii2-readonly-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Read Only Behavior for ActiveRecord Models
==========================================

[](#read-only-behavior-for-activerecord-models)

This behavior class allows you to specify an attribute which, upon setting or being set, prevents the model from being changed. Think of it as a latch that locks the model once a particular value has been set and saved.

This is intended to act as a failsafe to prevent a fixed record from being updated even if you make a mistake in the controller and allow a change to be made.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require synatree/yii2-readonly-behavior "*"

```

or add

```
"synatree/yii2-readonly-behavior": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by adding the behavior to your ActiveRecord model:

```
use synatree\behaviors\ReadOnlyBehavior;
...
public function behaviors(){
	return [
		'readonly' => [
			'class' => ReadonlyBehavior::className(),
			'attribute' => 'setmeonce',
			'onError' => function($param, $value){
				Yii::warning("Already Set, cannot set $param");
				throw new \yii\web\UnauthorizedHttpException("Already Set");
			}
		]
	];
}
```

Options
-------

[](#options)

```
	'attribute' => 'modelattr', // your model attribute that will trigger a lock.  Lock will take effect when the record is loaded from or saved to the database.
	'onError' => ... // callable, either a function, function name, etc. per PHP manual is_callable
	'stopEvent' => true, // stop the AR event that tried to change an attribute.  If false, the db record will be updated, but the values will be the same as when locked.
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5013f51d2f9796b9f6e8487e4bebae5ed5e8f3f753cced498c23e871c4481251?d=identicon)[synatree](/maintainers/synatree)

---

Top Contributors

[![synatree](https://avatars.githubusercontent.com/u/7294077?v=4)](https://github.com/synatree "synatree (10 commits)")

### Embed Badge

![Health badge](/badges/synatree-yii2-readonly-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/synatree-yii2-readonly-behavior/health.svg)](https://phpackages.com/packages/synatree-yii2-readonly-behavior)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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