PHP code example of akiraz2 / yii2-blog

1. Go to this page and download the library: Download akiraz2/yii2-blog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akiraz2 / yii2-blog example snippets


    'modules' => [
        'blog' => [
            'class' => akiraz2\blog\Module::class,
            'urlManager' => 'urlManager',// 'urlManager' by default, or maybe you can use own component urlManagerFrontend
            'imgFilePath' => '@frontend/web/img/blog/',
            'imgFileUrl' => '/img/blog/',
            'userModel' => \common\models\User::class,
            'userPK' => 'id', //default primary key for {{%user}} table
            'userName' => 'username', //uses in view (may be field `username` or `email` or `login`)
        ],
     ],    

    'timeZone' => 'Europe/Moscow', //time zone affect the formatter datetime format
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [               
            ],
        ],
        'formatter' => [ //for the showing of date datetime
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => '.',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
        ],
    ],

    'modules' => [
        'blog' => [
            'class' => 'akiraz2\blog\Module',
            'controllerNamespace' => 'akiraz2\blog\controllers\backend',
            //'adminAccessControl' => 'common\components\AdminAccessControl', // null - by default 
        ],
    ],

    //'defaultRoute' => 'blog', //set blog as default route
    'modules' => [
        'blog' => [
            'class' => 'akiraz2\blog\Module',
            'controllerNamespace' => 'akiraz2\blog\controllers\frontend',
            'blogPostPageCount' => 6,
            'blogCommentPageCount' => 10, //20 by default
            'enableComments' => true, //false by default
            'schemaOrg' => [ // empty array [] by default! 
                'publisher' => [
                    'logo' => '/img/logo.png',
                    'logoWidth' => 191,
                    'logoHeight' => 74,
                    'name' => 'My Company',
                    'phone' => '+1 800 488 80 85',
                    'address' => 'City, street, house'
                ]
            ]
        ],
    ],

./yii migrate --migrationPath=@akiraz2/blog/migrations

./yii migrate --migrationPath=@vendor/akiraz2/yii2-blog/migrations

...
'components' => [
    'view' => [
        'theme' => [
            'pathMap' => [
                '@akiraz2/yii2-blog/views/frontend/default' => '@app/views/blog'
            ],
        ],
    ],
],
...
  
'modules' => [
        'blog' => [
            'class' => akiraz2\blog\Module::class,            
            'userModel' => \common\models\User::class,
            'userPK' => 'id', //default primary key for {{%user}} table
            'userName' => 'username', //uses in view (may be field `username` or `email` or `login`)
        ],
     ],   
 

     'modules' => [
         'blog' => [
             'class' => 'akiraz2\blog\Module',
             'controllerNamespace' => 'akiraz2\blog\controllers\backend',
             'redactorModule' => 'redactor' // 'redactorBlog' - default, maybe you want use standard module 'redactor' with own config
         ],
         'redactor' => [
             'class' => 'yii\redactor\RedactorModule',
             'uploadDir' => '@frontend/web/img/upload/',
             'uploadUrl' => $params['frontendHost'] . '/img/upload',
             'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg']
         ],
     ],
 

    'modules' => [
         'blog' => [
             'class' => akiraz2\blog\Module::class,
             ...
             'adminAccessControl' => 'common\components\AdminAccessControl',  
             ...      
         ],
     ], 
 
 
    namespace common\components;
    
    use yii\filters\AccessControl;
    
    class AdminAccessControl extends AccessControl
    {    
        public function init()
        {
            $this->rules[] =[
                'allow' => true,
                'roles' => ['@'],
                'matchCallback' => function () {
                    return \Yii::$app->user->identity->getIsAdmin();
                }
            ];
            parent::init();
        }
    }
 

    'components' => [
        'opengraph' => [
            'class' => 'dragonjet\opengraph\OpenGraph',
        ],
        //....
    ],
  

php ./yii message/extract @akiraz2/blog/messages/config.php

php composer.phar