Alright, SilverStripe again, still our CMS of choice.
Today i’d like to promote a very helpful module that provides Register and Profile Pages for Members for the Frontend.
The memberprofiles module.
It comes with a lot of features and customize options for nearly everthing you might need for Frontend Member Handling.
Further it is fully extendible to customize it even more.
For a starter tutorial i recommend a very good post by deadlytechnology.
I would like to describe how you extend it.
First lets install it (with the orderable module dependency):
cd my_silverstripe_project git clone https://github.com/ajshort/silverstripe-orderable.git mv silverstripe-orderable/ orderable git clone http://github.com/ajshort/silverstripe-memberprofiles.git mv silverstripe-memberprofiles/ memberprofiles
Run /dev/build?flush=all
At this point i like to skip the further setup, for this, go read the post recommended above.
So now lets extend f.e. the Register Page for the Member to provide a custom template for a custom member, say: Customer, and some additional logic.
Just make a new file mysite/code/CustomerRegisterPage.php:
class CustomerRegisterPage extends MemberProfilePage { ... } class CustomerRegisterPage_Controller extends MemberProfilePage_Controller { ... }
and a template: themes/mytheme/CustomerRegisterPage.ss
In this template you can now add your markup and include the MemberProfileForm via $RegisterForm.
Or make your own Form by overwriting the RegisterForm in the Controller or make a complete new Form.
To register the template with the extended Page we have to overwrite the index method in the controller.
public function index() { if (isset($_GET['BackURL'])) { Session::set('MemberProfile.REDIRECT', $_GET['BackURL']); } return $this->renderWith(array('CustomerRegisterPage', 'Page')); }
Now we overwrite the register method to add some additional logic, f.e. to add a custom DataObject from a many_many relation from the customer Member.
public function register($data, Form $form) { if ($member = $this->addMember($form)) { if (isset($data['OptionsID'])) { foreach ($data['OptionsID'] as $key => $value) { $member->Options()->setByIDList($data['OptionsID']); } } return $this->redirect($this->Link('afterregistration')); } else { return $this->redirectBack(); } }
Thats it!
Now create a new CustomerRegisterPage in the backend and do as you learned from deadlytechnology.