SwiftMailer:如何将学生成绩报告发送给其监护人


SwiftMailer: How To Send Result Report Of Student To His Guardian

我正在尝试发送学生的成绩报告和费用提醒给他们的父母。但问题是,我不明白如何从DailyReport实体中逐一获取DailyReport,从Parent实体中获取父母的电子邮件。

我花了好几个小时才把它修好,但没有成功。

因为SwiftMailerBunlde只渲染那些在SchoolBundle/Resources/views/Default/email.html.twig和我的小树枝模板schoolFinal/app/Resources/views/dailyreport/index.html.twig .

我尝试创建学生实体的对象,但它抛出错误,student不存在于SchoolBundle/Resources/views/Default/email.html.twig

        $message= 'Swift_Message::newInstance()
        ->setSubject('Testing Mail')
        ->setFrom('test@gmail.com')
        ->setTo($student->getGuardian()->getEmail())
        ->setCharset('utf-8')
        ->setContentType('text/html')
        ->setBody($this->renderView('SchoolSMSBundle:student:dailyreport.html.twig'));
    $this->get("mailer")->send($message);

这是我的dailyreport.html.twig文件

<h1>Daily Report</h1>
<table>
    <tbody>
    <tr>
        <th>Id</th>
        <td>{{ dailyReport.id }}</td>
    </tr>
    <tr>
        <th>Total Marks</th>
        <td>{{ dailyReport.total }}</td>
    </tr>
    <tr>
        <th>Obtained</th>
        <td>{{ dailyReport.obtained }}</td>
    </tr>
    </tbody>
</table>
<ul>
    <li>
        <a href="{{ path('school_dailyReport_index') }}">Back to the list</a>
    </li>
    <li>
        <a href="{{ path('school_dailyReport_edit', { 'id': dailyReport.id }) }}">Edit</a>
    </li>
    <li>
        {{ form_start(delete_form) }}
        <input type="submit" value="Delete">
        {{ form_end(delete_form) }}
    </li>
</ul>

按如下方式在renderView中传递数据后,它工作了。

 ->setBody($this->renderView('SchoolSMSBundle:Default:dailyReport.html.twig', array('dailyReport'=>$dailyReport)));