[英]symfony2 service why inject param is string?
Hi i created a service and when i try ti use it i got an error 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
嗨,我创建了一个服务,当我尝试使用它时,我收到一个错误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
why is that ? 这是为什么 ? here is my service: 这是我的服务:
/**
* @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;
}
}
Try to use this includes on the top of page: 尝试在页面顶部使用此包含:
use JMS\DiExtraBundle\Annotation\Inject;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\DiExtraBundle\Annotation\Service;
/**
* @Service("local_adapter")
*/
class LocalAdapter
{
// other your code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.