PHPackages                             inblank/yii2-seobility - 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. inblank/yii2-seobility

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

inblank/yii2-seobility
======================

Behavior for Yii2 to manage SEO data for ActiveRecord

0.1.1(10y ago)152[2 issues](https://github.com/inblank/yii2-seobility/issues)MITPHP

Since May 14Pushed 10y ago2 watchersCompare

[ Source](https://github.com/inblank/yii2-seobility)[ Packagist](https://packagist.org/packages/inblank/yii2-seobility)[ Docs](https://github.com/inblank/yii2-seobility)[ RSS](/packages/inblank-yii2-seobility/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Behavior for Yii2 to manage SEO data for ActiveRecord
=====================================================

[](#behavior-for-yii2-to-manage-seo-data-for-activerecord)

[![Build Status](https://camo.githubusercontent.com/5635910cf39997133854ca56499d265779bc1fc6b6ad3ceff464830e1a673776/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e626c616e6b2f796969322d73656f62696c6974792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/inblank/yii2-seobility)[![Packagist Version](https://camo.githubusercontent.com/9a321cf462bd453db45d97c4f56cd62ee06859ac3e17d1222f37596fc777f3ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e626c616e6b2f796969322d73656f62696c6974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/inblank/yii2-seobility)[![Code Coverage](https://camo.githubusercontent.com/60f6f5d854be105101fe604c3c82d13e5562c9d65c0ff86f58b9ee684e731b90/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f696e626c616e6b2f796969322d73656f62696c6974792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/inblank/yii2-seobility/?branch=master)[![Code Quality](https://camo.githubusercontent.com/8eded37ea30b417e69c971335cb52d804862db7eaff63e69d0c54149e8cf361d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696e626c616e6b2f796969322d73656f62696c6974792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/inblank/yii2-seobility/?branch=master)[![GitHub license](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/inblank/yii2-seobility/master/LICENSE)

> **[Русская версия](https://github.com/inblank/yii2-seobility/blob/master/README_RU.md)** этого документа доступна [здесь](https://github.com/inblank/yii2-seobility/blob/master/README_RU.md).

Behavior `yii2-seobility` for Yii2 allows you to manage SEO data for ActiveRecord models. For each model, you can store multiple records with SEO data and select according to the condition. If data with the condition not found, then will returned the default data, and if them not, will returned the data with empty values.

Each SEO data entry contains the fields: `title`, `keywords` and `description`.

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

[](#installation)

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

Navigate to the project folder and run the console command:

```
$ composer require inblank/yii2-seobility
```

or add:

```
"inblank/yii2-seobility": "~0.1"
```

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

Configuring
-----------

[](#configuring)

### Database

[](#database)

To storing SEO data the behavior uses an ActiveRecord model's database connection. Behavior does not create and does not check for required tables. Tables must be created before using.

The name of the table to store and retrieve data, the behavior has on the basis of the table name of the ActiveRecord model to which is attached. The name is created by adding the suffix `_seo` to the table name of the ActiveRecord model. To get the table name of the model the model uses the method `ActiveRecord::tableName()`

> **Examples:**
>
> - If the model uses a table `model`, the behaviour will use the table `model_seo`.
> - If the model uses a table `{{%model}}`, the behaviour will use the table `{{%model_seo}}`.

To create a table use the following SQL query, replacing `model_seo` by required table name:

> The query uses the [MySQL](http://dev.mysql.com/doc/refman/5.7/en/) syntax

```
CREATE TABLE `model_seo`(
    `model_id` INT NOT NULL DEFAULT 0,
    `condition` INT NOT NULL DEFAULT 0,
    `title` TEXT NOT NULL,
    `keywords` TEXT NOT NULL,
    `description` TEXT NOT NULL,

    PRIMARY KEY (`model_id`, `condition`)
);
```

### Model

[](#model)

To use a behavior just attach it to the ActiveRecord model as specified in the [Yii2 documentation](http://www.yiiframework.com/doc-2.0/guide-concept-behaviors.html)

```
use inblank\seobility\SeobilityBehavior;

/**
 * ...
 */
class Model extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            SeobilityBehavior::className(),
        ];
    }
}
```

If you correctly created a table to store the SEO data, configuring is complete.

Usage
-----

[](#usage)

After successful configuration, you can use behavior methods to manage SEO data of ActiveRecord models.

### Setting default SEO data

[](#setting-default-seo-data)

> Default SEO data have condition=0

To setting default SEO data:

```
$model = Model::findOne(1);

// set data by the behavior method
$model->setSeobility([
    'title' => 'SEO title for model',
    'keywords' => 'model, seo, keywords, yii2',
    'description' => 'Simple model with SEO data'
]);

// ... or by direct access
$model->seobility = [
    'title' => 'SEO title for model',
    'keywords' => 'model, seo, keywords, yii2',
    'description' => 'Simple model with SEO data'
];

// not necessarily set all field for SEO data
// code below set only `title` field
$model->seobility = [
    'title' => 'Chnaged SEO title',
];

// need to save model to store all setting SEO data
$model->save();
```

After saving the model, the default SEO data will contain defined values and these will be available at any time.

> **Note**: If the model has not passed validation and was not saved SEO data will not be saved too.

### Setting SEO data with condition

[](#setting-seo-data-with-condition)

To setting SEO data with condition:

```
$model = Model::findOne(1);

// setting a data with condition is only possible through the method of behavior
// set SEO data for condition=1
$model->setSeobility([
    'title' => 'Another SEO title',
    'keywords' => 'model, seo, keywords, yii2',
    'description' => 'This description is different'
], 1);

// need to save model to store all setting SEO data
$model->save();
```

> **Note**: If the model has not passed validation and was not saved SEO data will not be saved too.

### Getting default SEO data

[](#getting-default-seo-data)

To getting default SEO data:

```
$model = Model::findOne(1);

// getting default data through the method of behavior
$seo = $model->getSeobility();

// ... or by direct access
$seo = $model->seobility;
```

After getting the data, the variable `$seo` will contain an array with keys `title`, `keywords` and `description`.

Data will be obtained even if they were not specified. In this case, all array fields will contain empty value.

### Getting SEO data with condition

[](#getting-seo-data-with-condition)

To getting SEO data with condition:

```
$model = Model::findOne(1);

// getting data with condition is only possible through the method of behavior
$seo = $model->getSeobility(1);
```

Will be obtained SEO data with `condition=1`, and if no such data will be getting the default SEO data, or empty if no default data.

Through the method parameters, you can specify what data to obtain if the requested data is not found.

```
// not get the default data if data with `condition=1` not found
// i.e. if the data with `condition=1` will not be found, it returns
// an array with empty values
$seo = $model->getSeobility(1, false);

// get data with `condition=2` if not found  data with `condition=1`
// and if not found data with `condition=1` will return an array with empty values
$seo = $model->getSeobility(1, true, 2);
```

### Getting all SEO data

[](#getting-all-seo-data)

To getting all SEO data:

```
$model = Model::findOne(1);

// getting all data
$seo = $model->getAllSeobility();
```

After getting the data, the variable `$seo` will contain an array with all the SEO data. Indices of elements in the array are the values of the `condition`.

### Remove default SEO data

[](#remove-default-seo-data)

To remove default SEO data:

```
$model = Model::findOne(1);

// remove default data
$seo = $model->deleteSeobility();
```

> **Attention**: Be careful, the removal happens immediately and does not require `$model->save()` method. Removed data cannot be restore.

### Remove SEO data with condition

[](#remove-seo-data-with-condition)

To remove SEO data with condition:

```
$model = Model::findOne(1);

// remove data with condition=1
$seo = $model->deleteSeobility(1);
```

> **Attention**: Be careful, the removal happens immediately and does not require `$model->save()` method. Removed data cannot be restore.

### Remove all SEO data for model

[](#remove-all-seo-data-for-model)

To remove all SEO data for model:

```
$model = Model::findOne(1);

// remove ALL model's SEO data
$seo = $model->deleteAllSeobility();
```

> **Attention**: Be careful, the removal happens immediately and does not require `$model->save()` method. Removed data cannot be restore.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

3698d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/433803cfd4ffaa6ed53792ce7596b33ebaf36b9fe111e4724c621cdb3f6dc288?d=identicon)[inblank](/maintainers/inblank)

---

Top Contributors

[![inblank](https://avatars.githubusercontent.com/u/693804?v=4)](https://github.com/inblank "inblank (9 commits)")

---

Tags

htmlyii2Behaviorseo

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/inblank-yii2-seobility/health.svg)

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

###  Alternatives

[v0lume/yii2-meta-tags

DB based model meta data for SEO

194.1k](/packages/v0lume-yii2-meta-tags)[daxslab/yii2-taggedview

Extension to help setup the standard HTML meta tags besides the ones defined by Opengraph and Twitter to contribute to website SEO

114.7k1](/packages/daxslab-yii2-taggedview)[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1831.2k](/packages/mdmsoft-yii2-autonumber)[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1175.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)[valentinek/yii2-closure-table-behavior

This extension allows you to get functional for closure table trees.

1615.4k](/packages/valentinek-yii2-closure-table-behavior)[umanskyi31/opengraph

Created a new component for Yii2. The Open Graph component for your website

119.8k](/packages/umanskyi31-opengraph)

PHPackages © 2026

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