PHPackages                             demi/seo - 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. demi/seo

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

demi/seo
========

Library for working with SEO parameters of models

1.2.2(5y ago)131.6k↓50%4GPL-3.0-or-laterPHPPHP &gt;=5.4.0

Since Jun 14Pushed 5y ago5 watchersCompare

[ Source](https://github.com/demisang/yii2-seo)[ Packagist](https://packagist.org/packages/demi/seo)[ Docs](https://github.com/demisang/yii2-seo#readme)[ RSS](/packages/demi-seo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

yii2-seo
========

[](#yii2-seo)

Library for working with SEO parameters of models

How it works:
-------------

[](#how-it-works)

You add 2 fields to you model:

- `seo_url` VARCHAR: it is unique model name, example: `http://example.com/post/`.
- `seo_meta` TEXT: it is serialized array: `['title' => 'Post title', 'desc' => 'Post description', 'keys' => 'Post title, other keywords...']`.

This behavior help you with:

- Generate `seo_url` from model title considering your unique-conditions.
- Internationalization for `seo_meta`.
- Get model view url by simple call `$model->viewUrl`. (return relative url `/post/my-first` and even `/cat1/cat2/awesome-post` is possible).
- Output model seo fields(internationalized) to html: ``, `` and ``
- Form fields for `seo_url` and all `seo_meta` and internationalizations fields if needed.
- You can(must) configure `seo_meta` fields generator, for example: keywords is: `, key1, key2, , ...`.

Examples of generated `seo_url` for some cases:

- `http://example.com/first-category/awesome-post` - post1, cat1, `seo_url` is `awesome-post`
- `http://example.com/other-category/awesome-post` - post2, cat2, `seo_url` is `awesome-post` also possible
- `http://example.com/first-category/awesome-post_` - post3, cat1, `seo_url` is `awesome-post_` (add underscore at end if name in post category already used)

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

[](#installation)

Run

```
composer require "demi/seo" "~1.0"

```

Configuration
-------------

[](#configuration)

Each view should have access to `demi\seo\SeoViewBehavior` methods. So configure `/frontend/config/main.php`:

```
return [
    'components' => [
        'view' => [
            'as seo' => [
                'class' => 'demi\seo\SeoViewBehavior',
                // options by default:
                'titleTemplate' => '{title} - {appName}',
                'descriptionTemplate' => '{description}',
                'keywordsTemplate' => '{keywords}',
            ]
        ],
    ],
];
```

In model file add seo model behavior:

```
