2016-09-22 102 views
-2

开始使用symfony并且遇到了服务问题。运行Symfony服务时遇到问题

... \程序\ CONFIG \ services.yml

app.pdf.service: 
    class: AppBundle\Service\PdfService 
    arguments: [format, orientation]] 

... \ SRC \的appbundle \服务\ PdfService.php

namespace AppBundle\Service; 

class PdfService 
{ 

    private $format; 
    private $orientation; 

    public function __construct($format, $orientation) 
    { 
     $this->format = $format; 
     $this->orientation = $orientation; 
    } 

} 

现在我尝试使用该服务附:

$this->container->get('app.pdf.service'); 

我忘了什么吗? $ this-> container-> get(ist working,cause I invoked the tcpdf/Service from whiteoctober/tcpdf-bundle。我将扩展这个服务,因为我需要更多的功能。 s00n n00n

+0

出现错误信息? – mblaettermann

+0

'arguments:[format,orientation]]' - >多余一个括号']'?? – yceruto

+0

thx,但只是一个复制和粘贴错误。在我的IDE中设置第二个支架。 – n00n

回答

0

假设格式和方向的参数是有严格规定,请尝试:

app.pdf.service: 
    class: AppBundle\Service\PdfService 
    arguments: ["%format%", "%orientation%"] 

的 “硬编码” 定义的例子:

app.pdf.service: 
    class: AppBundle\Service\PdfService 
    arguments: ["a4", "landscape"] 

查看官方文档以获得详细信息: https://symfony.com/doc/current/components/dependency_injection.html#setting-up-the-container-with-configuration-files

+0

不,它不工作,也许别的东西在服务可用之前进行配置。似乎该服务在容器内不可用。 – n00n

相关问题