PHPackages                             yii2tech/content - 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. [Templating &amp; Views](/categories/templating)
4. /
5. yii2tech/content

AbandonedArchivedYii2-extension[Templating &amp; Views](/categories/templating)

yii2tech/content
================

Content management system for Yii2

1.0.1(8y ago)552.9k5BSD-3-ClausePHP

Since Aug 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/yii2tech/content)[ Packagist](https://packagist.org/packages/yii2tech/content)[ RSS](/packages/yii2tech-content/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

 [ ![](https://avatars2.githubusercontent.com/u/12951949) ](https://github.com/yii2tech)

Content management system for Yii2
==================================

[](#content-management-system-for-yii2)

This extension provides content management system for Yii2.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/a0ef4b2c9355e75798bb1157f7bedf8dc1070f49d05df2c44bcbd2dbce22faf4/68747470733a2f2f706f7365722e707567782e6f72672f79696932746563682f636f6e74656e742f762f737461626c652e706e67)](https://packagist.org/packages/yii2tech/content)[![Total Downloads](https://camo.githubusercontent.com/893a8acad042bed5e39f54134af81a13551db749533fb0134cb69cb9c8d425e5/68747470733a2f2f706f7365722e707567782e6f72672f79696932746563682f636f6e74656e742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yii2tech/content)[![Build Status](https://camo.githubusercontent.com/a89bf286ce2f230a5c7e5c84bbc839a38c6fc2dee64f431139593e2e9a4809f8/68747470733a2f2f7472617669732d63692e6f72672f79696932746563682f636f6e74656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2tech/content)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist yii2tech/content

```

or add

```
"yii2tech/content": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

This extension provides basic content management system for Yii2. There is a common task to provide ability for application administrator to change site content, like static pages ('About us', 'How it works' and so on), email templates and so on. This task is usually solved by developer using a dedicated database entities (tables) to store static page or email template contents. However using just database entities creates a several problems like defining default (pre-filled) data or updating existing application. In case you need to setup a default pre-set for static pages, so the deployed application does not look empty or add extra static page to the existing site with pre-filled content, you'll need to manipulate database records using DB migration mechanism or something. This is not very practical - it would be better to be able to control list of static pages or email templates inside program code under the VSC (Git, Mercurial etc).

This extension solves the content management task using 'override' principle: the default set of content is defined by the source code files, while there is an ability to override default contents using database storage.

This extension provides a special Yii application component - \[\[\\yii2tech\\content\\Manager\]\], which provides high level interface for content management. Manager operates by 2 content storages:

- \[\[\\yii2tech\\content\\Manager::$sourceStorage\]\] - uses project source files as a default contents source
- \[\[\\yii2tech\\content\\Manager::$overrideStorage\]\] - uses DBMS storage to override source contents

Application configuration example:

```
return [
    'components' => [
        'pageContentManager' => [
            'class' => 'yii2tech\content\Manager',
            'sourceStorage' => [
                'class' => 'yii2tech\content\PhpStorage',
                'filePath' => '@app/data/pages',
            ],
            'overrideStorage' => [
                'class' => 'yii2tech\content\DbStorage',
                'table' => '{{%Page}}',
                'contentAttributes' => [
                    'title',
                    'body',
                ],
            ],
        ],
    ],
    // ...
];
```

In this example default contents for the static pages located in the project files under directory '@app/data/content'. Each record is represented by the separated file, like following:

```
