2rats / yii2-forum
Installs: 230
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.4.0
- 2rats/yii2-markdown: @dev
- kartik-v/yii2-grid: @dev
- kartik-v/yii2-widget-select2: @dev
- yii2mod/yii2-markdown: *
- yiisoft/yii2: ~2.0.45
- yiisoft/yii2-bootstrap5: 2.0.3
- yiisoft/yii2-imagine: ~2.2.0
Requires (Dev)
- phpstan/phpstan: 1.11.x-dev
This package is auto-updated.
Last update: 2024-11-17 22:24:04 UTC
README
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
-
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
Module configuration
Configuration options of the module in config/web.php
.
Parameters configuration
Module behavior can also be modified by adding parameters in your configuration file config/params.php
.
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.