bishopb / laravel-forums
Laravel的论坛和讨论板,使用Vanilla Forums引擎。
Requires
- bishopb/vanilla: 2.2.3.6-patch1
- felixkiss/uniquewith-validator: 1.1.*
- laravel/framework: ~4.2
- watson/validating: 0.10.*
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2021-04-04 19:40:49 UTC
README
一个基于Vanilla Forums引擎构建的Laravel 4论坛包。
你可能需要此包,如果你
- 需要一个集成到你的Laravel应用中的顶级论坛解决方案,并且
- 你太忙或者太懒,不愿意自己编写一个,并且可选的
- 你想通过编程方式创建论坛用户、讨论板、公告墙等。
听起来正是你所需要的?那么这就是你的包!我们以Laravel开发者会喜欢的方式打包了优秀的Vanilla Forums。
- 将其组合到你的应用中,就像其他任何包一样。
- 使用Eloquent模型访问Vanilla数据库表。
- 使用模板修改外观和感觉。
- 使用典型的配置文件配置论坛。
警告:此包为预alpha版本,正在积极开发中。请报告问题并注意BC破坏。
要求
你需要
安装
编辑你的composer.json
以包含
"require": { "bishopb/laravel-forums": "~0.1" },
运行composer update bishopb/laravel-forums --no-dev
。
将包服务提供者添加到你的app/config/app.php
'providers' => array ( // ... other providers here 'BishopB\Forum\ForumServiceProvider', ),
安装迁移:php artisan forum:migrate
连接Vanilla和Laravel:php artisan forum:connect
导航到/forum
路由。你应该看到一个没有帖子的论坛,以“匿名”身份登录。点击“新建讨论”开始对话。恭喜你,你现在有一个基本的论坛,任何人都可以发表帖子。
下一步是决定你的应用用户如何映射到论坛。继续阅读。
将应用用户映射到论坛用户
你的应用有用户。Vanilla论坛的引擎也有。这两个用户集是兼容的,但可能不是一对一映射。因此,你需要明确定义这两个如何映射。
Laravel论坛提供了三种映射策略
- 通过主键一对一映射
- 按需同步
- 自定义闭包
通过主键一对一映射
这是默认设置。Vanilla用户通过主键与应用程序用户匹配,例如“User.id == GDN_User.UserID”。在这个策略中,你必须在你创建、修改或删除应用程序用户时创建、修改和删除Vanilla用户。以下代码将帮助你开始
use \BishopB\Forum\User; use \BishopB\Forum\UserRepository; use \BishopB\Forum\RoleRepository; function create_an_app_user() { // make this app user a member moderator $user = UserRepository::createWithRoles( [ 'Name' => 'Jane Q. Doe', 'Password' => User::crypt_password('the-initial-password', 'vanilla'), 'HashMethod' => 'vanilla', ], [ RoleRepository::member(), RoleRepository::moderator() ] ); }
按需同步
这是最容易开始的,但可能效率不高。这个策略要么为应用程序用户创建一个新的Vanilla用户以进行匹配,要么更新Vanilla用户以反映应用程序用户中的当前数据。如果没有应用程序用户,可以选择定义一个访客用户。
// in app/start.php use \Illuminate\Auth\UserInterface as AppUser; use \BishopB\Forum\User as VanillaUser; \App::bind('BishopB\Forum\UserMapperInterface', function () { $mapper = new \BishopB\Forum\UserMapperSynchronicity(); $mapper->create_guest_account = null; // when null, guests will not be able // to access the forums. Change to a // closure to implement $mapper->create_account_for = function ($vanillaID, AppUser $user) { return UserRepository::createWithRoles( [ 'UserID' => $vanillaID, 'Name' => $user->lastCommaFirstName, 'Password' => str_random(64), 'HashMethod' => 'random', ], [ RoleRepository::member() ] ); }; $mapper->update_account_for = function (AppUser $user, VanillaUser $vanillaUser) { $vanillaUser->Name = $user->lastCommaFirstName; $vanillaUser->save(); }; return $mapper; });
自定义映射
正如其名:自定义。您可以随心所欲地做任何事。
\App::bind('BishopB\Forum\UserMapperInterface', function () { $mapper = new \BishopB\Forum\UserMapperByClosure(); $mapper->setClosure(function (\Illuminate\Auth\UserInterface $user = null) { // do whatever you want, it should return a \BishopB\Forum\User }); return $mapper; });
视图和主题
所有视图都位于 views/themes/default
文件夹中。请按照 views/themes/default/README.md
中的说明开始操作。
一个需要注意的点。这些视图直接来自Vanilla,并基于 Smarty。它可能没有blade那么容易,但同样强大。
事件
Vanilla 在运行过程中会触发事件,您可以使用这些事件来响应或修改Vanilla的运行方式。首先,了解 Vanilla 插件开发。然后,捕获这些事件
\Event::listen('forum.event', function ($data) { // use $data according to the plugin guidelines });
故障排除
事情可能会出错。至少有一种方法可以查看引擎内部,了解Vanilla正在做什么。请看这里
- 发布包配置文件:
php artisan config:publish bishopb/laravel-forums
- 编辑
app/config/packages/bishopb/laravel-forums/package.php
- 将这些标志设置为
true
:trace
,trace-include-events
,trace-include-queries
。 - 查看您的
app/storage/logs/laravel.log
获取详细信息。
常见问题解答
- 这个包提供了什么? 简而言之,为Laravel提供的论坛软件。使用令人惊叹的Vanilla Forums引擎,您的Laravel应用程序现在可以快速轻松地包含讨论板。
- 它是免费的吗? 当然是。
- 它可以做什么? 如果Vanilla Forums的社区版可以做到,这个包也可以做到,但可能目前还不能。
- 这个包与Vanilla Forums之间存在哪些“差距”? 这可能不是完整的列表:插件。