PHPackages                             infoweb-internet-solutions/yii2-cms - 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. [Framework](/categories/framework)
4. /
5. infoweb-internet-solutions/yii2-cms

ActiveYii2-extension[Framework](/categories/framework)

infoweb-internet-solutions/yii2-cms
===================================

CMS module for Yii2

2.0.2(10y ago)461.7k18[24 issues](https://github.com/infoweb-internet-solutions/yii2-cms/issues)8MITPHP

Since Sep 29Pushed 9y ago18 watchersCompare

[ Source](https://github.com/infoweb-internet-solutions/yii2-cms)[ Packagist](https://packagist.org/packages/infoweb-internet-solutions/yii2-cms)[ RSS](/packages/infoweb-internet-solutions-yii2-cms/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (35)Versions (43)Used By (8)

CMS module for Yii 2
====================

[](#cms-module-for-yii-2)

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

[](#installation)

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

You can then install the application using the following command:

```
php composer.phar global require "fxp/composer-asset-plugin:~1.0"
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced advanced
```

### Configure environments

[](#configure-environments)

Create a new dev and production database and adjust the `components['db']` configuration in `environments/dev/common/config/main-local.php` and `environments/prod/common/config/main-local.php` accordingly.

Remove the `components['mailer']` configuration from both files because it will be added to `common/config/main.php`

Add to `environments/prod/common/config/main-local.php`

```
'controllerMap' => [
	'migrate' => [
		'class' => 'fishvision\migrate\controllers\MigrateController',
		'autoDiscover' => true,
		'migrationPaths' => [
			'@vendor'
		],
	],
],
```

### Update composer.json file

[](#update-composerjson-file)

Update the `config` section of `composer.json` if you want composer to download git folders for the packages

```
"config": {
    ...
	"preferred-install": "source"
},
```

Add the `infoweb-internet-solutions/yii2-cms` and `fishvision/yii2-migrate` packages

```
"require": [
    ...
    "fishvision/yii2-migrate": "*",
    "infoweb-internet-solutions/yii2-cms": "*"
]
```

Add references to the custom repositories that are needed to override certain vendor packages

```
...
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/infoweb-internet-solutions/yii2-i18n-module"
    },
    {
        "type": "vcs",
        "url": "https://github.com/infoweb-internet-solutions/yii2-ckeditor"
    }
]
...
```

Add following rule to filter bower/npm packages that can be skipped (it will make sure you won't get a out of memory and it will decrease the needed time to update your project).

```
...
"extra": {
    ...
    "asset-pattern-skip-version": "(-patch)"
}
```

Check if `"minimum-stability": "dev"` is set

After this run `composer update` to install the package

### Init environment

[](#init-environment)

Create folders in `frontend/web/`

```
uploads/img
uploads/files

```

and add `.gitignore` file in `uploads/`

```
*
!.gitignore

```

Remove `adminEmail` and `supportEmail` in `backend/config/params.php`, `common/config/params.php`, `frontend/config/params.php` and `console/config/params.php` and at them to `environments/dev/common/config/params-local.php` and `environments/prod/common/config/params-local.php`

Run command `init` to initialize the application with a specific environment.

Usage
-----

[](#usage)

Once the extension is installed, simply modify `common/config/main.php` as follows:

```
use \kartik\datecontrol\Module;

return [
	...
    'name' => 'My Application',
    'language' => 'nl',
    'timeZone' => 'Europe/Brussels',
    ...
    'components' => [
        ...
        'cache' => [
            'class' => 'yii\caching\DbCache',
        ],
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
        ],
        // Rewrite url's
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName'  => false,
        ],
        // Formatter
        'formatter' => [
            'dateFormat' => 'php:d-m-Y',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
        ],
        // Override views
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@dektrium/user/views' => '@infoweb/user/views'
                ],
            ],
        ],
      	'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@infoweb/cms/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'host',
                'username' => 'user',
                'password' => 'password',
                'port' => 'port'
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
                [
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['error'],
                ],
                [
                    'class' => 'yii\log\EmailTarget',
                    'levels' => ['error'],
                    'categories' => ['yii\db\*'],
                    'message' => [
                       'from' => ['info@domain.com'],
                       'to' => ['developer@domain.com'],
                       'subject' => '[MySQL error @ domain.com]',
                    ],
                ],
            ],
        ],
		'i18n' => [
			'class' => Zelenin\yii\modules\I18n\components\I18N::className(),
			'languages' => ['nl']
		],
    ],
    ...
    'modules' => [
        'datecontrol' =>  [
            'class' => 'kartik\datecontrol\Module',

            // format settings for displaying each date attribute (ICU format example)
            'displaySettings' => [
                Module::FORMAT_DATE => 'php:d-m-Y',
                Module::FORMAT_TIME => 'php:H:i',
                Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss',
            ],

            // format settings for saving each date attribute (PHP format example)
            'saveSettings' => [
                Module::FORMAT_DATE => 'php:U', // saves as unix timestamp
                Module::FORMAT_TIME => 'php:H:i:s',
                Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
            ],

            // set your display timezone
            'displayTimezone' => 'Europe/Brussels',

            // set your timezone for date saved to db
            'saveTimezone' => 'Europe/Brussels',

            // automatically use kartik\widgets for each of the above formats
            'autoWidget' => true,

            // default settings for each widget from kartik\widgets used when autoWidget is true
            'autoWidgetSettings' => [
                Module::FORMAT_DATE => ['pluginOptions' => [
                    'autoclose' => true,
                    'todayHighlight' => true,
                    //'todayBtn' => true
                ]],
                Module::FORMAT_DATETIME => [], // setup if needed
                Module::FORMAT_TIME => [], // setup if needed
            ],
            // Use custom convert action
            'convertAction' => '/cms/parse/convert-date-control'
        ],
		'yii2images' => [
			'class' => 'rico\yii2images\Module',
			'imagesStorePath' => '@uploadsBasePath/img', //path to origin images
			'imagesCachePath' => '@uploadsBasePath/img/cache', //path to resized copies
			'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
			'placeHolderPath' => '@infoweb/cms/assets/img/transparent-placeholder.png',
		],
    ],
    ...
    'params' => [
        // Font Awesome Icon framework
        'icon-framework' => 'fa',
    ],
];
```

(dont forget to update the settings of the **mailer**, **log** and **i18n** components!)

`backend/config/main.php` as follows:

```
return [
    ...
	'name' => 'My application',
	...
    'bootstrap' => ['log','cms'],
    ...
    'modules' => [
    	...
        'cms' => [
            'class' => 'infoweb\cms\Module',
        ],
       	'gridview' =>  [
            'class' => '\kartik\grid\Module'
        ],
  	    'media' => [
            'class' => 'infoweb\cms\Module',
        ],
		'email' => [
            'class' => 'infoweb\email\Module'
        ],
		'admin' => [
			'class' => 'mdm\admin\Module',
		],
		'i18n' => [
            'class' => Zelenin\yii\modules\I18n\Module::className(),
        ],
		'settings' => [
            'class' => 'infoweb\settings\Module'
        ],
		'pages' => [
			'class' => 'infoweb\pages\Module',
        ],
		'partials' => [
			'class' => 'infoweb\partials\Module',
		],
		'seo' => [
			'class' => 'infoweb\seo\Module',
		],
		'menu' => [
            'class' => 'infoweb\menu\Module',
        ],
		'alias' => [
			'class' => 'infoweb\alias\Module',
			'reservedUrls' => ['page'] // Url's that are reserved by the application
		],
    ],
    ...
    'components' => [
        ...
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@app/views/layouts' => '@infoweb/cms/views/layouts',
                    '@dektrium/user/views' => '@infoweb/user/views'
                ],
            ],
        ],
		'request' => [
            'class' => 'common\components\Request',
            'web'=> '/backend/web',
            'adminUrl' => '/admin'
        ],
    ],
    ...
];
```

`backend/config/params.php` as follows:

```
return [
    ...
    // Moximanager settings
    'moxiemanager'  => [
        'license-key'   => 'your-moxiemanager-key'
    ],
    ...
]
```

and `common/config/params.php` as follows:

```
return [
    ...
    // Enabled languages
    'languages' => [
        'nl'    => 'Nederlands',
        'fr'    => 'Français',
        'en'    => 'English',
    ],
    'companyName'   => 'YourCompany'
    ...
];
```

and `frontend/config/main.php` as follows:

```
return [
    ...
    'components' => [
		'user' => [
            'identityClass' => 'infoweb\user\models\frontend\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'request'=>[
            'class' => 'common\components\Request',
            'web' => '/frontend/web',
            'csrfParam' => '_frontendCSRF',
        ],
        // Override the urlManager component
        'urlManager' => [
            'class' => 'codemix\localeurls\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '404'               => 'site/error',
                '' => 'site/index',
            ],
        ],
        'page' => [
            'class' => 'infoweb\pages\components\Page'
        ]
    ],
	...
];
```

Docs
----

[](#docs)

Follow all usage instructions
Do not run composer, all modules are included in the infoweb-cms composer file and should be already installed
Do not run any migrations and don't import messages, we'll do this later

- [Installation user module](https://github.com/infoweb-internet-solutions/yii2-cms-user)
- [Installation analytics widget](https://github.com/infoweb-internet-solutions/yii2-cms-analytics)

Add a couple of system aliases to `common/config/bootstrap.php`

```
...
// System aliases
Yii::setAlias('baseUrl', 'http://' . ((isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : '') . ((YII_ENV_DEV) ? '/directory-in-your-localhost' : ''));  [
	'migrate' => [
		'class' => 'fishvision\migrate\controllers\MigrateController',
		'autoDiscover' => true,
		'migrationPaths' => [
			'@vendor'
		],
	],
],
```

```
yii migrate/up
```

Import the translations

```
yii i18n/import @infoweb/cms/messages --interactive=0
yii i18n/import @Zelenin/yii/modules/I18n/messages --interactive=0
yii i18n/import @infoweb/settings/messages --interactive=0
yii i18n/import @infoweb/pages/messages --interactive=0
yii i18n/import @infoweb/partials/messages --interactive=0
yii i18n/import @infoweb/seo/messages --interactive=0
yii i18n/import @infoweb/alias/messages --interactive=0
yii i18n/import @infoweb/analytics/messages --interactive=0
yii i18n/import @infoweb/email/messages --interactive=0
yii i18n/import @infoweb/sliders/messages --interactive=0
```

Yii messages import fails sometimes, try importing without --interactive=0 and keep hitting return until it's done

```
yii i18n/import @yii/messages
```

Add htaccess files

Root

```

    Options +FollowSymlinks
    RewriteEngine On

    # deal with admin first
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
    RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
    RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]

    RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^.*$ backend/web/index.php [L]

    RewriteCond %{REQUEST_URI} ^/(assets|css)
    RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
    RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
    RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]

    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
    RewriteCond %{REQUEST_URI} !index.php
	RewriteCond %{REQUEST_URI} !^/preview
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ frontend/web/index.php

# Optional

# Upload limit
php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_execution_time 6000
php_value max_input_time 2400
php_value max_file_uploads 100

php_value memory_limit 256M

```

backend/web/

```
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

Options FollowSymLinks
```

frontend/web/

```
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L] # Remove trailing slash

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
```

Add new file`frontend/web/css/editor.css`

```
body {
    padding: 15px;
}
```

Add new class in `common/components/Request.php`

```
