【发布时间】:2020-08-06 04:27:46
【问题描述】:
在我的 Symfony 应用程序中,我有一个订阅者,其中我需要遍历存储在数组中的 IRI 并访问其实体的方法。我该怎么做?
例如:
function sendMail ($event) {
...
$instance = $event->getControllerResult();
...
$recipients = $instance->getRecipients(); // returns array of IRIs
foreach ($recipients as $recipient) {
$r = // instance of IRI-associated entity
if ($r instanceof User) {
// send to user
$email = $r->getEmail();
// send an email
} else if ($r instanceof Group) {
// send to group
foreach ($r->getUsers() as $user) {
$email = $user->getEmail();
// send an email
}
}
}
...
}
虽然我可能忽略了它,但我没有在文档中找到这样做的方法,而且我对 Symfony 的了解仍在增长。
【问题讨论】:
标签: php symfony4 api-platform.com