I want to create a Logout link in my Concrete 5.7 theme.
What function do I call to generate that URL, seeing as it contains special security tokens?
I want to create a Logout link in my Concrete 5.7 theme.
What function do I call to generate that URL, seeing as it contains special security tokens?
This function should generate a logout URL:
URL::to('/login', 'logout', \Core::make('helper/validation/token')->generate('logout'));
If you only want to show it when the user is actually logged in, you can combine it with this if
statement:
if (!(new User())->isLoggedIn()) {
$url = URL::to('/login');
} else {
$url = URL::to('/login', 'logout',
\Core::make('helper/validation/token')->generate('logout'));
}
In 5.7+ you should no longer use Loader
, it should all use Core::make()
so we can take the code from @simon-east and change it like so:
if (!(new User())->isLoggedIn()) {
$url = URL::to('/login');
} else {
$url = URL::to('/login', 'logout', \Core::make('helper/validation/token')->generate('logout'));
}