簡體   English   中英

Symfony sensio/framework-extra-bundle 已被放棄,我找不到 IsGranted 替代方案

[英]Symfony sensio/framework-extra-bundle is abandoned and i cannot find an IsGranted alternative

(在 Symfony 5.4 PHP 7.4 項目上)
到目前為止,我使用IsGranted來限制每個角色在控制器中的訪問。 IE

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
class PostController extends Controller
{
    /**
     * @IsGranted("ROLE_ADMIN")
     */
    public function myAdminPage()
    { // ... }
}

由於composer update ie: Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.上的abandoned警告被廢棄,你應該避免使用它。 Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead. 我正在嘗試尋找替代方案。

對於Route注釋的情況,通過替換是直接的:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Symfony\Component\Routing\Annotation\Route;

但我找不到IsGranted的替代方案。 (對於 Symfony 5 或 Symfony 6)

有什么建議/建議嗎?
謝謝。

這個:

 use Symfony\Component\Security\Http\Attribute\IsGranted;

https://symfony.com/doc/current/security.html#securing-controllers-and-other-code

在 Symfony 5.4 中,您應該改用Security組件。

use Symfony\Component\Security\Core\Security;

class PostController extends Controller
{
    /**
     * @Security("is_granted('ROLE_ADMIN')")
     */
    public function myAdminPage()
    { 
        // ... 
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM