简体   繁体   English

如何阅读config / app.php中定义的“电子邮件”选项?

[英]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? 我是否必须以其他方式阅读它们?

Comsumed configuration is being deleted 消耗的配置被删除

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. 在某些时候某些配置正在“消耗”,默认情况下,当前是CacheDatasourcesEmailTransportEmailLogSecurity.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

Retrieve the configuration from the consumers 从使用者那里检索配置

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版本。

See also 也可以看看

在CakePHP版本> 3.4中,您必须使用

\Cake\Mailer\Email::getConfigTransport('smtp');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM