Skip to content

Instantly share code, notes, and snippets.

@DorsetDigital
Created February 10, 2020 13:14
Show Gist options
  • Save DorsetDigital/640b62a1cadb6c64196a6ef3fa897ead to your computer and use it in GitHub Desktop.
Save DorsetDigital/640b62a1cadb6c64196a6ef3fa897ead to your computer and use it in GitHub Desktop.
class MyMemberPage extends \Page
{
private static $table_name = 'MyMemberPage';
private static $controller_name = MyMemberPageController::class;
}
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Security\Security;
class MyMemberPageController extends \PageController
{
// This is where you tell the controller what actions it can perform. Each would be in the URL (eg. /memberpage/delete)
private static $allowed_actions = [
'save',
'delete',
'confirm'
];
public function delete(HTTPRequest $request)
{
$accountId = $request->getVar('account');
$account = Accounts::get()->byID($accountId);
if ($account->AccountOwnerID === Security::getCurrentUser()->ID) {
//You can delete the account here
}
}
public function getAccounts()
{
return Security::getCurrentUser()->Accounts();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment