porcelanosa/yii2-posts

The module is mostly for the backend, but partly for the frontend too.

Installs: 14

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2017-11-21 21:45 UTC

README

Module for different type of post, like articles, news, blog post etc. ERR Diagram

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'

 
    ......
    'modules' => [
        'posts' => [
            'class' => 'porcelanosa\posts\Module',
        ],
    ],
    ......

3. Backend config

Add to 'backend/config/main.php

'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. Migration

Run migration

yii migrate --migrationPath=@vendor/porcelanosa/yii2-posts/migrations

5. Routes

Add rules to UrlManager For example,

// 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'

6. Add module to bootstrap

Add

'bootstrap'           => ['posts'],

to common/config/main.php