我在Symfony中设置服务时遇到问题。运行应用程序时出现以下错误:
The autoloader expected class "HRPortal\SystemBundle\Services\SessionHandler" to be
defined in file "/usr/local/apache2/htdocs/hrportal/src/HRPortal/SystemBundle/Services/SessionHandler.php".
The file was found but the class was not in it, the class name or namespace probably has a typo.
该课程如下:
<?php
namespace HRPortal\SystemBundle\Services\SessionHandler;
class SessionHandler
{
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function init($user)
{
...
}
....
}
我的服务声明如下:
parameters:
session_handler.class: HRPortal\SystemBundle\Services\SessionHandler
services:
session_handler:
class: "%session_handler.class%"
我尝试了很多不起作用的东西,所以我想我会问社区,看看你能发布什么。
谢谢
答案 0 :(得分:3)
命名空间应该是
namespace HRPortal\SystemBundle\Services;
这样,完全限定的类名称为HRPortal\SystemBundle\Services\SessionHandler