[英]How to read the 'Email' options defined in config/app.php?
I'm trying to read the email options defined in config/app.php
, using Configure::read('Email');
我正在尝试使用
Configure::read('Email');
config/app.php
定义的电子邮件选项Configure::read('Email');
, but it returns null
. ,但返回
null
。 Other options can be read just fine using Configure::read(<options name>)
. 使用
Configure::read(<options name>)
可以很好地读取其他选项。
I think reading the Email
options is being blocked somehow. 我认为阅读“
Email
选项被某种方式阻止了。 How can I read the Email
options from the configuration defined in config/app.php
using Configure::read()
? 如何使用
Configure::read()
从config/app.php
定义的config/app.php
读取“ Email
选项? Do I maybe have to read them in a different way? 我是否必须以其他方式阅读它们?
Some configuration is being "consumed" at some point, by default that currently is Cache
, Datasources
, EmailTransport
, Email
, Log
, and Security.salt
, see your applications config/bootstrap.php
file. 在某些时候某些配置正在“消耗”,默认情况下,当前是
Cache
, Datasources
, EmailTransport
, Email
, Log
和Security.salt
,请参阅您的应用程序config/bootstrap.php
文件。
https://github.com/cakephp/app/blob/3.2.4/config/bootstrap.php#L146-L151 https://github.com/cakephp/app/blob/3.2.4/config/bootstrap.php#L146-L151
Consuming keys results in them being deleted after they have been read, so after that point in your bootstrap there will be no Email
config anymore, and consequently you'll receive null
when trying to read it. 使用密钥会导致在读取密钥后将其删除,因此在引导程序中此点之后将不再有
Email
配置,因此在尝试读取密钥时会收到null
。
If you want to access such configuration at a later point, then you should access it via the classes that consumed it, in your case the Email
class, ie read it via 如果您想在以后访问此类配置,则应通过使用它的类(在您的情况下为
Email
类)来访问它,即通过
\Cake\Network\Email\Email::config() // (CakePHP < 3.1)
or 要么
\Cake\Mailer\Email::config() // (CakePHP >= 3.1)
depending on your CakePHP version. 取决于您的CakePHP版本。
在CakePHP版本> 3.4中,您必须使用
\Cake\Mailer\Email::getConfigTransport('smtp');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.