PHPackages                             sjaakp/yii2-novelty - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sjaakp/yii2-novelty

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

sjaakp/yii2-novelty
===================

Property indicating novelty of Yii2 ActiveRecord.

1.0.1(1y ago)2511MITPHP

Since Jul 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sjaakp/yii2-novelty)[ Packagist](https://packagist.org/packages/sjaakp/yii2-novelty)[ RSS](/packages/sjaakp-yii2-novelty/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

yii2-novelty
============

[](#yii2-novelty)

Property indicating novelty of Yii2 ActiveRecord
------------------------------------------------

[](#property-indicating-novelty-of-yii2-activerecord)

[![Latest Stable Version](https://camo.githubusercontent.com/ab87944396f1755c6195cabab7a31c5e1247bf7f4f03c3db79612c14c9e8b851/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d6e6f76656c74792f762f737461626c65)](https://packagist.org/packages/sjaakp/yii2-novelty)[![Total Downloads](https://camo.githubusercontent.com/bb3d6ec7cf006e171a1e2013f9f9d0b2f32967534adca7a32c7c02d8c1c2e78e/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d6e6f76656c74792f646f776e6c6f616473)](https://packagist.org/packages/sjaakp/yii2-novelty)[![License](https://camo.githubusercontent.com/c5f70091380335c2c03b3353c19e9debea00a52804c7cac2e5e151db4d5b184d/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d6e6f76656c74792f6c6963656e7365)](https://packagist.org/packages/sjaakp/yii2-novelty)

**yii2-novelty** is a [behavior](https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors#behaviors "Yii2")that adds a property with the name `'novelty'` to an [ActiveRecord](https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#active-record "Yii2")in the [Yii2](https://www.yiiframework.com/ "Yii2") PHP framework. This property has one of the following three values:

- `'new'` in case the record is *created* since the user visited the site previously;
- `'updated'` in case the record is *updated* since the user visited the site previously;
- `null` in other cases.

The class **NoveltyBehavior** extends om Yii's [TimestampBehavior](https://www.yiiframework.com/doc/api/2.0/yii-behaviors-timestampbehavior "Yii2"). The value of `novelty` is based on the attribute values of TimestampBehavior, usually called `'created_at'` and `'updated_at'`, and on the time the user visited the site previously. The previous visit time is stored in two cookies.

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

[](#installation)

Install **yii2-novelty** in the usual way with [Composer](https://getcomposer.org/). Add the following to the require section of your `composer.json` file:

`"sjaakp/yii2-novelty": "*"`

or run:

`composer require sjaakp/yii2-novelty`

You can manually install **yii2-novelty** by [downloading the source in ZIP-format](https://github.com/sjaakp/yii2-novelty/archive/master.zip).

Using NoveltyBehavior
---------------------

[](#using-noveltybehavior)

Add **NoveltyBehavior** to your ActiveRecord like this:

```
