This Yii2 extension offers a simple set of forum features that make it easy to integrate a full-featured forum into your web application.
- PHP 7.4 or higher
- Yii2 Framework
- Yii2 RBAC
- User table migration
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"
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
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
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',
];
-
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.
-
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 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 |
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 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.