模板是视图(就普通页面而言)电子邮件的布局是视图的布局(就普通页面而言)
布局应该包含一些常见的元素,如标志等
您可以将数据推送到模板,例如推送数据以从控制器查看
请检查以下示例:
来自自定义 EmailComponent
public function restore_password($user_to_send_restore_link) {
$email = new CakeEmail('default');
$email->emailFormat('both');
$email->template('restore_password', 'emaillayout');
$email->to(array($user_to_send_restore_link['User']['email']));
$email->from(array(GENERAL_FROM_EMAIL => 'seqrd support team'));
$subject = 'Restore password link';
$email->subject($subject);
$email_data = array(
'hash' => $user_to_send_restore_link['User']['hash']);
$email->viewVars($email_data);
return $email->send();
}
应用程序/查看/电子邮件/html/restore_password.ctp
<p> Please, follow link <?php echo $this->Html->link('restore password link', Router::url(array('controller' => 'users', 'action' => 'restore_password_form', $hash), true)); ?> to restore password</p>
应用程序/视图/布局/电子邮件/html/emaillayout.ctp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo $title_for_layout;?></title>
</head>
<body>
<?php echo $this->fetch('content');?>
</body>
</html>
主题是抽象的下一步,您可以快速更改所有电子邮件的整体样式,但不会显着更改代码。
注意: viewVars
方法不仅将变量传递给模板,还传递给电子邮件布局。