Create local pages

v2.1.0 2017-08-30 14:40 UTC


Create multi language static pages


The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist shoxabbos/yii2-localpages "*"

or add

"shoxabbos/yii2-localpages": "*"

to the require section of your composer.json file.


Once the extension is installed, simply use it in your code by :

Run migrate

php yii migrate --migrationPath=@vendor/shoxabbos/yii2-localpages/migrations

Add module to web/config

'modules' => [
    'pages' => [
        'class' => '\shoxabbos\localpages\Module',
        'langs' => [
            'ru' => 'Russian',
            'en' => 'English',
        'defaultRoute' => 'page',
        'defaultLang' => 'ru',
        'layoutPath' => '@app/path/to/layouts',
        'layout' => 'admin',
        'pagesTableName' => 'pages',
        'pagesContentTableName' => 'page_contents',

Add action to your controller (viewFile: your view file for showing pages)

public function actions()
    return [
        'page' => [
            'class' => 'shoxabbos\localpages\actions\ViewAction',
            'viewFile' => 'page'

For add news: http://localhost:8080/pages/page/create

For see created your post: http://localhost:8080/site/page?slug=test

If you want a nice url you can set up the URL manager:

'page/<slug:\w+>' => 'site/page'

After that, you can open the pages as:

Before: http://localhost:8080/site/page?slug=test

After: http://localhost:8080/page/test