a2nt / silverstripe-member-profiles
SilverStripe可扩展的用户资料区域。提供注册页面和可扩展的用户资料页面区域。
Requires
- silverstripe/cms: >=3.1
- silverstripe/framework: >=3.1
This package is not auto-updated.
Last update: 2024-09-14 19:42:20 UTC
README
维护者联系方式
- Anton Fedianin <tony (at) twma (dot) pro> https://twma.pro
需求
- SilverStripe 3.2
概述
前端用户资料区域的一个简化、轻量级替代方案。
- 注册页面
- 更新详情的用户资料页面。
- 可扩展的用户资料区域
注册页面
在CMS中创建成员注册页面或在模块安装后运行 /dev/build?flush
用户资料页面
在CMS中创建成员用户资料页面或在模块安装后运行 /dev/build?flush
资料区域
默认情况下,资料区域只有资料信息和资料编辑表单控制器,要添加额外的资料区域,请使用此示例。
class MyProfileArea extends MemberProfilePage_Controller { /* ... your code * private static $allowed_actions = [ * 'MyAction' * ]; * * public function MyAction() {} * */ }
资料信息将使用 /profile URL,子控制器将使用此页面的子-URL,例如:/profile/myprofilearea /profile/myprofilearea/action
/profile/myprofileareaCRUD/MyItemClassName/new/ /profile/myprofileareaCRUD/MyItemClassName/view/11 /profile/myprofileareaCRUD/MyItemClassName/edit/11 /profile/myprofileareaCRUD/MyItemClassName/delete/11 /profile/myprofileareaCRUD/extraaction/ID/OtherID
新区域将自动添加到前端用户资料区域导航菜单中,但您可以通过添加 hide ancestor 来隐藏它。
class MyProfileArea extends ProfileController { private static $hide_ancestor = false; // it's optional if you want to hide this controller set to true private static $menu_icon = '<i class="fa fa-pencil-square-o"></i>'; // optional icon private static $menu_title = 'My Profile Area'; // optional title otherwise My Profile Area title will be used }
需求配置示例
ProfileController: requirements_css: - site/css/ProfileController.css requirements_javascript: - site/css/ProfileController.js
资料CRUD
class MyProfileObjectsController extends ProfileCRUD { /* * This controller will let you create, view, edit and delete objects */ private static $hide_ancestor = false; // it's optional if you want to hide this controller set to true private static $menu_icon = '<i class="fa fa-pencil-square-o"></i>'; // optional icon private static $menu_title = 'My Profile Area'; // optional title otherwise My Profile Area title will be used private static $managed_models = [ 'MyObject', 'MyObject2', ]; private static $allowed_actions = [ 'ExtraAction' ]; public function ExtraAction() {} }
-
为了创建 "MyProfileArea" 模板,创建 templates/profile/controllers/MyProfileArea.ss
-
它将用作 MemberProfilePage.ss 的子模板,通过使用 $ProfileArea 变量,就像 $Layout 需要Page.ss的子模板一样。
-
为了创建 "MyProfileArea" 的特定动作模板,创建 templates/profile/controllers/MyProfileArea_MyAction.ss
使用以下代码来自定义 MemberRegistrationForm
MemberRegistrationForm: extensions: - MyMemberRegistrationFormExtension
class MyMemberRegistrationFormExtension extends Extension { public function updateMemberRegistrationForm() { /* your code, ex: * $fields = $this->owner->Fields(); * $fields->push(TextField::create('MyField')); * BootstrapForm::apply_bootstrap_to_fieldlist($fields); * BootstrapForm::apply_bootstrap_to_fieldlist($this->owner->Actions()); */ } public function onRegister($member) { /* your code to execute on register for an instance extra notifications */ } }
使用以下代码来自定义 MemberEditProfileForm
MemberEditProfileForm: extensions: - MyMemberEditProfileFormExtension
class MyMemberEditProfileFormExtension extends Extension { public function updateMemberEditProfileForm() { /* your code, ex: * $fields = $this->owner->Fields(); * $fields->push(TextField::create('MyField')); * BootstrapForm::apply_bootstrap_to_fieldlist($fields); * BootstrapForm::apply_bootstrap_to_fieldlist($this->owner->Actions()); */ } }
使用以下代码来扩展资料CRUD项目表单
ProfileCRUD: extensions: - BootstrapItemEditForm
class BootstrapItemEditForm extends Extension { public function permissionDenied() { // your code, for example: Page_Controller::setSiteMessage('You must log in to view your profile.', 'warning'); } public function updateItemRemoved(DataObject $item) { // your code } public function updateItemRemoveDenied() { // your code } public function updateItemEditDenied() { // your code } public function updateItemEditSuccess(DataObject $item, array $data, $new = false) { if ($new) { $success_msg = 'New Item Created'; } else { $success_msg = 'Item was updated'; } // your code } public function updateItemForm($form) { $fields = $form->Fields(); // setup bootstrap classes BootstrapForm::apply_bootstrap_to_fieldlist($fields); $fields = $form->Actions(); // setup bootstrap classes BootstrapForm::apply_bootstrap_to_fieldlist($fields); } }