[英]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.