0

I got the message

Did you forget to run "composer require symfony/security-core"? Unknown function "is_granted" in "...".

when calling template-code

{% if is_granted(constant('Rights::RGT_TOUR_ADD')) %}...{% endif %}

I am using symfony v5.3.7, symfony/security-core and symfony/twig-bridge are both v5.3.7. twig itself is v3.3.2 (just updated the whole stuff). All packages are installed in the "good way" of "symfony composer require..."

There is a bunch of extensions in /vendor/symfony/twig-bridge/Extension and most of them are loaded, but not the SecurityExtension (even though available).

Of course I don't want to hard-code a solution, due to the fact that it would be done in /vendor which is in .gitignore ;)

I already tried forced reinstalling of the package... No change.

Just in case this info is needed... PHP is v7.4.15 x64

3
  • How did you install the packages? Did you also enable the bundles properly? Flex will automatically do this for you, but if you're not using Flex, you need to enable the bundles manually Commented Sep 14, 2021 at 12:58
  • Are you using the actual Symfony framework? How exactly did you create your app? Commented Sep 14, 2021 at 12:59
  • Flex is installed (1.15.4) and the packages work well within symfony... Just the extension is missing (the security-http is missing, too. So logout_path isn't working in twig). Everything is up to date, I am using the latest version. Commented Sep 14, 2021 at 13:47

1 Answer 1

0

Security bundle doesn't have logout_path. You need controller action with the path having that name:

<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;


class SecurityController extends AbstractController
{
    /**
     * @Route("/logout", name="logout_path")
     */
    public function logout()
    {
        throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
    }
}

As for is_granted check if symfony/security-bundle is installed, enabled in config/bundles.php, and configured properly in config/packages/security.yaml.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.