Posts Module
Module for different type of post, like articles, news, blog post etc.
, (*1)
Dependencies
use \kartik\switchinput\SwitchInput;
use mihaildev\ckeditor\CKEditor;
use mihaildev\elfinder\ElFinder;
"porcelanosa/yii2-toggle-column": "*",
Installation
1. Run composer
composer require porcelanosa/yii2-posts
2. Common config
Add to 'common/config/main.php', (*2)
......
'modules' => [
'posts' => [
'class' => 'porcelanosa\posts\Module',
],
],
......
3. Backend config
Add to 'backend/config/main.php, (*3)
'module' => [
...
'posts' => [
'class' => 'porcelanosa\posts\Module',
'controllerMap' => [
'cpposts' => [
'class' => 'porcelanosa\posts\controllers\AdminController',
'as access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
],
],
],
],
],
...
If you rename CintrollerMap name from 'cpposts' you must rename 'modules/posts/views/cppost/' folder also., (*4)
4. Migration
Run migration, (*5)
yii migrate --migrationPath=@vendor/porcelanosa/yii2-posts/migrations
5. Routes
Add rules to UrlManager
For example,, (*6)
// posts with post_types 'articles'
[
'pattern' => 'articles',
'route' => 'posts/default/index',
'defaults' => ['post_type_slug' => 'articles'],
],
[
'pattern' => 'articles/<cat_slug>/<slug>',
'route' => 'posts/default/view',
'defaults' => ['post_type_slug' => 'articles'],
],
// posts with post_types 'news'
[
'pattern' => 'news',
'route' => 'posts/default/index',
'defaults' => ['post_type_slug' => 'news'],
],
[
'pattern' => 'news/<cat_slug>/<slug>',
'route' => 'posts/default/view',
'defaults' => ['post_type_slug' => 'news'],
],
//'confirm-order' => 'cart/confirmorder',
// Posts
[
'pattern' => 'posts/<post_type_slug>/<cat_slug>/<slug>',
'route' => 'posts/default/view'
],
[
'pattern' => 'posts/<post_type_slug>/<cat_slug>',
'route' => 'posts/default/catview'
],
[
'pattern' => 'posts/<post_type_slug>',
'route' => 'posts/default/index'
],
or different for route to 'posts/default/view', (*7)
6. Add module to bootstrap
Add, (*8)
'bootstrap' => ['posts'],
to common/config/main.php, (*9)