nill / forum
yii2-integration-phpBB3.1
This package is not auto-updated.
Last update: 2024-10-02 08:35:39 UTC
README
本扩展旨在将phpBB 3.1.x与Yii2集成。扩展用于同步登录、注册和编辑个人资料数据,如电子邮件地址和密码。使用了yii2-users-module作为用户模型,但您可以连接并配置您自己的模型行为。
关于
版本 0.3.7
作者:yiiframework.ru, Felix Manea, Äìèòðèé Åëèñååâ, Mefistophell Nill
用途
- Yii框架2.x
- Yii-Start应用程序 - yii2-start-users (https://github.com/vova07/yii2-users-module)
- phpBB 3.1.x
集成
第1部分:通过Composer安装
安装此扩展的首选方式是通过composer。
运行以下命令:
php composer.phar require nill/forum "dev-master"
或者
"nill/forum": "dev-master"
将其添加到您的composer.json文件的require部分。
从存档文件安装
- 添加文件夹
/vendor/nill/forum/
GitHub: yii2-integration-phpBB3.1
-
下载并解压文件到创建的目录
-
添加到扩展
/vendor/yiisoft/extensions.php
'nill/forum' =>
array (
'name' => 'nill/forum',
'version' => '0.1.0.0',
'alias' =>
array (
'@nill/forum' => $vendorDir . '/nill/forum',
),
),
第2部分:添加组件并设置配置
- 将组件添加到配置
/common/config/main.php
'phpBB' => [
'class' => 'nill\forum\phpBB',
'path' => dirname(dirname(__DIR__)). '\forum',
],
- 添加
request并更改组件配置中的user
'user' => [
'class' => 'nill\forum\PhpBBWebUser',
'loginUrl'=>['/login'],
'identityClass' => 'vova07\users\models\frontend\User',
// enable cookie-based authentication
// 'allowAutoLogin' => true,
],
'request' => [
'baseUrl' => $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'] != $_SERVER['SCRIPT_FILENAME'] ? 'http://' . $_SERVER['HTTP_HOST'] : '',
],
第3部分:更改论坛设置
- 将方法
get_container_filename()更改为\forum\phpbb\di\container_builder.php
protected function get_container_filename() {
// Change the line to synchronize with the site
// $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path);
$filename = str_replace(array('\\', '/', '.'), array('slash', 'slash', 'dot'), $this->phpbb_root_path);
return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext;
}
- 在数据库表
frm_config中查找并更改字段cookie_domain为您的域名:example -domain.loc
注意:此选项也在缓存文件中,如果不起作用,请清除缓存。
第4部分:向用户模型添加行为
####更改用户模型
- 将以下代码添加到User类顶部
use nill\forum\behaviors\PhpBBUserBahavior;
和
/**
* The variables required for integration with the forum
* @var string $password_reg - old password
* @var string $password_new - new password
*/
public $password_reg;
public $password_new;
- 在方法
getId之前添加或更改以下代码
/**
* Behavior PhpBBUserBahavior necessary for integration with the forum
*/
public function behaviors() {
return [
'PhpBBUserBahavior' => [
'class' => PhpBBUserBahavior::className(),
'userAttr' => 'username',
'newpassAttr' => 'password_new',
'passAttr' => 'password',
'emailAttr' => 'email',
],
];
}
如果您使用yii2-start-users,请按照以下说明操作
- 更改以下方法
public function validatePassword($password) {
$this->password_reg = $password;
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
和
public function password($password) {
$this->password_new = $password;
$this->setPassword($password);
return $this->save(false);
}
- 在
\vendor\vova07\users\models\frontend\PasswordForm.php中注释或删除以下代码 - 在
\vendor\vova07\users\models\frontend\Email.php中注释或删除以下代码
此字符串
use vova07\users\models\User;
FORUM在模板yii2
1. 在文件夹\forum中创建文件yiiapp.php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/aliases.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../common/config/main.php'),
require(__DIR__ . '/../common/config/main-local.php'),
require(__DIR__ . '/../frontend/config/main.php'),
require(__DIR__ . '/../frontend/config/main-local.php')
);
if ('YII_ENV_DEV') {
$config['components']['assetManager']['basePath'] = '@app/web/assets';
}
\Yii::setAlias('@app', '/../');
$application = new yii\web\Application($config);
2. 在文件夹\frontend\views\layouts\中创建文件forum.php。这是论坛模板。
<?= $content ?>
**3. 在文件\forum\index.php的顶部添加以下代码
//************************ FORUM Yii **********************************
include "yiiapp.php";
$controller = new yii\web\Controller('7','forum');
\Yii::$app->controller = $controller;
ob_start();
//************************ ********* **********************************
此代码应用于论坛的所有通用页面,例如:viewforum.php、viewtopic.php...
4. 在文件\forum\includes\functions.php的末尾添加以下代码到page_footer()函数中:(行:5310)
garbage_collection();
//************************ FORUM Yii **********************************
if (class_exists('Yii', false) && \Yii::$app->controller !== null) {
$content = ob_get_clean();
echo \Yii::$app->controller->render('//layouts/forum', ['content' => $content]);
}
//************************ ********** **********************************
if ($exit_handler)
{
exit_handler();
}
如果不起作用,则
在文件forum\phpbb\request\request.php中更改以下字符串
protected $super_globals_disabled = false; 到 protected $super_globals_disabled = true; (行:44)
同步
同步对于网站用户与论坛之间的关联是必要的。
将以下行添加到用户模型中
use nill\forum\models\phpBBUsers;
public function getPhpbbuser()
{
return $this->hasOne(phpBBUsers::className(), ['username' => 'username']);
}
示例视图
<?php $models = User::findOne(Yii::$app->user->id); ?>
Your Messages <a href="/forum/ucp.php?i=pm&folder=inbox">New: <?php if($models) echo $models->phpbbuser->user_unread_privmsg; ?></a>