当我在Symfony 3.4中更改为自动接线设置时,发生了以下错误
我所做的工作是从$this->get('security.authorization_checker')
到$authChecker
,以及从" ":"src/"
到"App\":"src/"
的composer.json psr-4
我相应地改变了树枝的路线。此外,我做了composer dump-autoload
是否有其他设置需要更改
SecurityController.php以外的generateUrl
似乎也不起作用bin/console debug:router
似乎很好
错误
Call to a member function get() on null
in ControllerTrait.php line 87
at Controller->generateUrl('app_ahi_sp_admin_hq_default_index', array(), 0)
in SecurityController.php line 40
SecurityController.php
namespace AppAhiSpAdminBundleController;
class SecurityController extends BaseController
{
/**
*
* @Route("/login")
* @Template("AppAhiSpAdminBundle:Security:login.html.twig")
*/
public function loginAction(Request $request, AuthorizationCheckerInterface $authChecker, TranslatorInterface $translator)
{
// Redirected to TOP if logged in
if ($authChecker->isGranted('ROLE_HQ_MANAGE')) {
return $this->redirect($this->generateUrl('app_ahi_sp_admin_hq_default_index', array(), UrlGeneratorInterface::ABSOLUTE_URL));
} elseif ($authChecker->isGranted('ROLE_SHOP_STAFF')) {
return $this->redirect($this->generateUrl('app_ahi_sp_admin_shop_default_index', array(), UrlGeneratorInterface::ABSOLUTE_URL));
}
}
services.yml
services:
# this makes public all the services defined in this file
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../../src/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/{Entity,Repository,Ahi/Sp/AdminBundle/Resources, Ahi/Sp/CommonBundle/Resources, Ahi/Sp/PublicBundle/ }'
AppAhiSpAdminBundleController:
resource: '../../src/Ahi/Sp/AdminBundle/Controller'
public: true
tags: ['controller.service_arguments']
路由.yml
app_ahi_sp_admin:
resource: '@AppAhiSpAdminBundle/Controller/'
type: annotation
prefix: /admin/
schemes: [http]
php bin/console router:match /admin/hq/
结果
$php bin/console router:match /admin/hq/
[OK] Route "app_ahi_sp_admin_hq_default_index" matches
+--------------+---------------------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------------------+
| Route Name | app_ahi_sp_admin_hq_default_index |
| Path | /admin/hq/ |
| Path Regex | #^/admin/hq/$#sD |
| Host | ANY |
| Host Regex | |
| Scheme | http |
| Method | GET |
| Requirements | NO CUSTOM |
| Class | SymfonyComponentRoutingRoute |
| Defaults | _controller: AppAhiSpAdminBundle:HqDefault:index |
| Options | compiler_class: SymfonyComponentRoutingRouteCompiler |
| Callable | AppAhiSpAdminBundleControllerHqDefaultController::indexAction |
php bin/console router
结果
$php bin/console router
app_ahi_sp_admin_hq_default_index GET https ANY /admin/hq/
我通过将SymfonyBundleFrameworkBundleControllerController
(BaseController的扩展目的地)设置为SymfonyBundleFrameworkBundleControllerAbstractController
来解决此问题。