Skip to content

A Yii2 extension that offers a simple set of forum features that make it easy to integrate a full-featured forum into your web application.

License

Notifications You must be signed in to change notification settings

2rats/yii2-forum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Forum Extension

This Yii2 extension offers a simple set of forum features that make it easy to integrate a full-featured forum into your web application.

⚠️ This extension is currently WIP. Feel free to Watch this repo for the first release or contribute. Thank you. ⚠️

Requirements

  • PHP 7.4 or higher
  • Yii2 Framework
  • Yii2 RBAC
  • User table migration

Instalation

This extension is designed to be used out of the box. Once you have installed the necessary migrations and configured the module in your application structure, you'll be ready to go.

The preferred way to install this extension is through composer.

composer require 2rats/yii2-forum "@dev"

Apply database migrations

1. User table and RBAC

First of all you have to setup and apply your User table and RBACK migration using:

php yii migrate
php yii migrate --migrationPath=@yii/rbac/migrations

2. Extension

Then you have to to apply migrations of this extension:

php yii migrate --migrationPath=@rats/forum/migrations
php yii migrate --migrationPath=@rats/forum/migrations/rbac

Modify database connection

This extension parses text emoji to unicode symbols (for example ':D' => '😃'). For proper saving to the database, it is necessary to have the correct charset both in the database settings and in the connection to the database in the config/db.php configuration file.

For example, you can use utf8mb4 charset.

<?php

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=test_db_name',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8mb4',
];

Modify signup method

  1. Open your application's signup process, where you create new users. This could be within a controller action, signup form or service that handles user registration.

  2. Inside your signup process, after creating the main user instance, call the ForumModule::signupUser function to create the associated forum user:

use rats\forum\ForumModule;

// ... Your signup process code ...

// After creating the main user, call the signupUser function to create the forum user.
ForumModule::signupUser($user);

Here, $user should be an instance of yours app\models\User.

If you are using the default Yii2 signup form, you can change it like this:

use rats\forum\ForumModule;

class SignupForm extends Model{

	// ... other code ...
	
	public function signup()
	{
	    if (!$this->validate()) {
	        return null;
	    }
	    $user = new User();
	    $user->username = $this->username;
	    $user->email = $this->email;
	    $user->setPassword($this->password);
	    $user->generateAuthKey();
	    $user->generateEmailVerificationToken();
	    
	    return $user->save() && $this->sendEmail($user) && ForumModule::signupUser($user);
	}
	
	// ... other code ...

}

Configuration

Module configuration

Configuration options of the module in config/web.php.

option default value description
userClass 'app\models\User' Class that represents app User.
The class must extend \yii\db\ActiveRecord
forumLayout 'forum' Layout that is used in forum sites
adminLayout 'admin' Layout that is used in administration of the forum

Parameters configuration

Module behavior can also be modified by adding parameters in your configuration file config/params.php.

option default value description
migrationTableOptions 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB' | null $options for createTable() function.
By default, it sets charset and engine for the mysql database driver, null for the others.
userTableName 'user' Table name of the Class, that represents app User.

Contributions

Contributions are highly appreciated. If you would like to contribute, please fork the repository, make your changes, and submit a pull request or open an issue.

Authors

License

BSD 3-Clause License

About

A Yii2 extension that offers a simple set of forum features that make it easy to integrate a full-featured forum into your web application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published