2

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?

4

2 回答 2

3

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'));
}
于 2016-01-27T03:35:28.300 回答
2

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'));
}
于 2016-04-08T23:16:50.360 回答