您好我创建了一项服务,当我尝试使用它时,我收到了一个错误
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Project\MyDriveBundle\Storage\LocalAdapter::__construct() must be an instance of Project\MainBundle\Manager\UserManager, string given, called in E:\wamp\www\project\src\Project\MyDriveBundle\Storage\LocalAdapter.php on line 41 and defined in E:\wamp\www\project\src\Project\MyDriveBundle\Storage\LocalAdapter.php line 38
为什么? 这是我的服务:
/**
* @Service("local_adapter")
*/
class LocalAdapter
{
/**
* @var Filesystem
*/
private $filesytem;
/**
* @var Adapter
*/
private $adapter;
/**
* @var UserManager
*/
protected $userManager;
/**
* @InjectParams({
* "userManager" = @Inject("manager.user")
* })
*/
public function __construct(UserManager $userManager)
{
$this->userManager = $userManager;
$this->adapter = new LocalAdapter('/' . $this->userManager->getUsername() . '/');
$this->filesytem = new Filesystem($this->adapter);
}
public function getFilesytem()
{
return $this->filesytem;
}
}
答案 0 :(得分:0)
尝试在页面顶部使用此包含:
use JMS\DiExtraBundle\Annotation\Inject;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\DiExtraBundle\Annotation\Service;
/**
* @Service("local_adapter")
*/
class LocalAdapter
{
// other your code