我有一个服务文件,包含以下几行代码。
namespace App\Service;
/**
* Class MyService
* @package App\Service
*/
class MyService
{
/**
* @var string
*/
private $newTest;
/**
* MyService constructor.
* @param string $newTest
*/
public function __construct(string $newTest)
{
$this->newTest = $newTest;
}
}
我把它定义在 service
部中 services.yaml
文件。
my_service:
class: App\Service\MyService
bind:
$pcValue: '%env(resolve:LATEST)%'
现在我正试图检索这个 pcValue
在控制器。
$this->get('my_service');
它返回给我以下错误。
`Service "my_service" not found: even though it exists in the app's container, the container inside "App\Controller\WheelController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.`