jcabanillas/yii2-blog

Yii2 Blog for other application

Installs: 41

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2017-06-05 19:25 UTC

README

Yii2 Blog for other application, especially for Yii2 Adminlte

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist jcabanillas/yii2-blog "dev-master"

or add

"jcabanillas/yii2-blog": "*"

to the require section of your composer.json file.

Migration

Migration run

yii migrate --migrationPath=@jcabanillas/blog/migrations

Config url rewrite in /common/config/main.php

    'timeZone' => 'Asia/Shanghai', //time zone affect the formatter datetime format
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ],
        ],
        'formatter' => [ //for the showing of date datetime
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'CNY',
        ],
    ],

Config backend modules in backend/config/main.php

    'modules' => [
        'blog' => [
            'class' => 'jcabanillas\blog\Module',
            'controllerNamespace' => 'jcabanillas\blog\controllers\backend'
        ],
    ],

Config frontend modules in frontend/config/main.php

    'defaultRoute' => 'blog', //set blog as default route
    'modules' => [
        'blog' => [
            'class' => 'jcabanillas\blog\Module',
            'controllerNamespace' => 'jcabanillas\blog\controllers\frontend'
        ],
    ],

Add yii2-blog params in /common/config/params.php.

return [
    'blogTitle' => 'HikeBlog',
    'blogTitleSeo' => 'Simple Blog based on Yii2',
    'blogFooter' => 'Copyright &copy; ' . date('Y') . ' by ahuasheng on Yii2. All Rights Reserved.',
    'blogPostPageCount' => '10',
    'blogLinks' => [
        'Google' => 'http://www.google.com',
        'jcabanillas Blog' => 'http://github.com/jcabanillas/yii2-blog',
    ],
    'blogUploadPath' => 'upload/', //default to frontend/web/upload
];

Access Url

  1. backend : http://you-domain/backend/web/blog
  2. frontend : http://you-domain/fontend/web/blog