【发布时间】:2018-01-22 13:43:13
【问题描述】:
在以下服务中注入服务时遇到问题: https://symfony.com/doc/current/service_container.html#injecting-services-config-into-a-service
这段代码:
namespace ServicesBundle\Services;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManagerInterface;
class Services
{
private $email;
public function __construct($email, $message, SessionInterface $sessInt) {
$this->email = $email;
$this->message = $message;
$this->sessInt = $sessInt;
}
public function DisplayMessage(){
return "This is the Services Class in the Services namespace. Email the administrator @ " . $this->email . " | " . $this->message;
}
public function sessionIdGetAction(){
$hello = $this->sessInt->getID();
return $hello;
}
}
抛出此错误:
类型错误:传递给 ServicesBundle\Services\Services::__construct() 的参数 3 必须实现接口 Symfony\Component\HttpFoundation\Session\SessionInterface,没有给出,在 /home/admin-daniel/symfony-test-sites 中调用/july262017/var/cache/dev/appDevDebugProjectContainer.php 第 412 行
当我从我的控制器调用这些函数中的任何一个时。
我迷路了。似乎我按照指南所说的但没有工作....
我在某处遗漏了一些东西......
【问题讨论】: