[英]Symfony3 Service container docs error
嘿所有我正在玩Symfony3,正在閱讀有關服務容器的文檔 。 根據文檔,服務在app / config / services.yml中聲明如下:
# app/config/services.yml
services:
app.mailer:
class: AppBundle\Mailer
arguments: [sendmail]
我可以在我的控制器/類中訪問它,如下所示:
<?php
namespace Test\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class HelloController extends Controller
{
public function sendEmailAction()
{
// ...
$mailer = $this->get('app.mailer');
var_dump($mailer);die();
// $mailer->send('ryan@foobar.net', ...);
}
}
我做過exacley,但是我收到了這個錯誤:
You have requested a non-existent service "app.mailer".
我在這個簡單的例子中做錯了什么我錯過了什么。
我還注意到Bundle / Resources / config.srvices.yml下還有另一個service / yml文件。 哪一個使用的時間和原因......?
服務app.mailer
似乎不存在。 您應該通過在cli: bin/console debug:container app.mailer
運行此命令來檢查它
我還注意到Bundle / Resources / config.srvices.yml下還有另一個service / yml文件。 哪一個使用的時間和原因......?
只有在捆綁包與其他應用程序/開源共享時,才應使用Bundle/Resources/config/*
。 如果沒有,請使用app/config/services.yml
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.