Yii2 Blog MongoDB
It's a multi-language blog extension that uses Mongodb that gives you an awesome performance., (*1)
Check this tutorial that I like, in order to know more about Mongodb., (*2)
Installation
- You have to have Mongodb up and running, so download it from here.
- Also you have to have Mongodb PHP driver installed.
And you run Mongodb through the following command:, (*3)
mongod --fork --logpath /var/log/mongodb/mongodb.log
-
And you setup the extension through the composer:, (*4)
composer require devmustafa/yii2-blog-mongodb, (*5)
Or add the following line in your composer.json:, (*6)
"devmustafa/yii2-blog-mongodb": "*"
Configuration
-
In your common config file add the following db component:, (*7)
...
'components' => [
...
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://127.0.0.1/DB_MONGO_NAME', // local
// 'dsn' => 'mongodb://DB_MONGO_USERNAME:DB_MONGO_PASSWORD@DB_MONGO_HOST/DB_MONGO_NAME, // remote
],
...
],
...
-
In your frontend config file add the following module:, (*8)
...
'modules' => [
...
'blog' => [
'id' => 'blog',
'class' => devmustafa\blog\modules\frontend\Module::className(),
'used_languages' => ['en', 'ar'], // list of languages used
'default_language' => 'en', // default language
'listing_size' => 10, // default size of listing page
'rules' => [ // setup rules for frontend routes
// change key not value
'posts' => '/post',
'post/<slug>' => '/post/single',
'category/<slug>' => '/post/category', // posts related to a specific category
]
],
...
]
...
-
In your backend config file add the following module:, (*9)
...
'modules' => [
...
'blog' => [
'id' => 'blog',
'class' => devmustafa\blog\modules\backend\Module::className(),
'upload_url' => 'http://example.com/uploads', // full upload url
'upload_directory' => '/full/path/to/uploads/dir', // full upload directory
'used_languages' => ['en', 'ar'], // list of languages used
'default_language' => 'en', // default language
],
...
]
...
Note:
default_language
must be one of your used_languages
array, and if you would like to use a dynamic language in your app, so leave it empty:, (*10)
'default_language' => '', // empty (don't remove)
In this case the extension reading the value of Yii::$app->langauge
and it should be one of your defined used_languages
array., (*11)
Usage
-
Go to your backend url to add some posts/authors/categories:, (*12)
- /blog/post
- /blog/author
- /blog/category
-
Then you check it out on your frontend:, (*13)