Wallogit.com
2017 © Pedro Peláez
Blogs Category module for Yii2-start
Blogs-Category module for Yii2-Start application., (*1)
This Module allows creating categories for the Blog., (*2)
There is also a widget that allows you to filter the blog posts by categories for the frontend., (*3)
Does not require to change Blog Module!, (*4)
Version: 0.9.1, (*5)
Authors: Mefistophell Nill, (*6)
public function setCategory()
{
$post = Yii::$app->request->post('Blog');
if (!$this->isNewRecord) {
Yii::$app->db->createCommand()->update('{{%blogs_to_category}}', ['category_id' => $post['category'], 'blog_id' => $this->id], ['blog_id' => $this->id])->execute();
return true;
}
}
The temporary decision. I shall be grateful for improvement., (*7)
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if (!$this->category) {
$post = Yii::$app->request->post('Blog');
Yii::$app->db->createCommand()->insert('{{%blogs_to_category}}', ['category_id' => $post['category'], 'blog_id' => $this->id], ['blog_id' => $this->id])->execute();
return true;
}
}
This module is used with Yii2-Start application yii2-start., (*8)
The preferred way to install this extension is through composer., (*9)
Either run, (*10)
php composer.phar require nill/yii2-blogs-category-module "dev-master"
or add, (*11)
"nill/yii2_blogs_category_module": "dev-master"
to the require section of your composer.json file., (*12)
Download and extract the zip-file into the folder with your project, (*13)
/my/path/to/yii2-start/vendor/nill/yii2_blogs_category_module
'blogs_category' => [
'isBackend' => true
],
'blogs_category' => [
'class' => 'nill\blogs_category\Module'
],
'nill/blogs_category' =>
array(
'name' => 'nill/yii2-blogs-category-module',
'version' => '0.1.0.0',
'alias' =>
array(
'@nill/blogs_category' => $vendorDir . '/nill/yii2-blogs-category-module',
),
'bootstrap' => 'nill\\blogs_category\\Bootstrap',
),
yii2_start_blogs_category.sql
yii2_start_blogs column: name: category_id type: int(11). This can be done by running the query SQL: ALTER TABLE yii2_start_blogs ADD category_id INT(11) NOT NULL;
OR: Apply migration with console commands:, (*14)
php yii migrate --migrationPath=@nill/blogs_category/migrations, (*15)
For work of the module in the backend follows add it to the menu:
vendor\vova07\yii2-start-themes\admin\views\layouts\sidebar-menu.php, (*16)
[
'label' => 'Blogs Category'),
'url' => ['/blogs_category/default/index'],
'icon' => 'fa-folder-open',
'visible' => Yii::$app->user->can('administrateBlogs') || Yii::$app->user->can('BViewBlogs'),
],