0

現在、Yii 1.1 プロジェクトに登録されているユーザーにシステム メールを送信できる機能を実装しています。

私は初心者の開発者なので、ヒントが必要な場合もあります。そのため、システム メッセージを送信するときに使用される電子メール テンプレート ファイルの保存と取得の実装についていくつか簡単な質問があります (たとえば、swiftMailer を使用します)。

  1. システム メッセージ用の HTML 電子メール テンプレートを格納するのに最適な Yii アプリケーションのフォルダはどれですか?
  2. 電子メール テンプレートはファイルとして保存され、モデルはデータベースと対話しないため、「電子メール テンプレート」モデルをどのクラスに拡張する必要がありますか。
  3. アプローチ (別の「メール テンプレート」モデル + メール テンプレート ファイルをシステムに保存する) は、この種のものに適していますか?

誰かが別のやり方を勧めることができれば、それも大歓迎です。

4

1 に答える 1

0

電子メールは、配信メカニズムが異なるだけで、他の種類のビューと同じです。Yii が期待するテンプレートの場所は次のとおりです。

yii/
-- protected/
   -- views/
      -- mail/
         -- template.html

メール用に Yii 内からテンプレートを指定できます。のドキュメントを参照してくださいYiiMailMessage->setBody

/**
* Set the body of this entity, either as a string, or array of view 
* variables if a view is set, or as an instance of 
* {@link Swift_OutputByteStream}.
* 
* @param mixed the body of the message.  If a $this->view is set and this 
* is a string, this is passed to the view as $body.  If $this->view is set 
* and this is an array, the array values are passed to the view like in the 
* controller render() method
* @param string content type optional. For html, set to 'html/text'
* @param string charset optional
*/

例:

$message = new YiiMailMessage;
$message->view = 'main_tpl';
$message->setBody(array(
    'data' => $data,
    'user' => $user,
));
$message->subject = $subject;
$message->addTo($email);
$message->from = $from;
Yii::app()->mail->send($message);

これにより、テンプレートを使用してメッセージが準備され、不足している部分を埋めるためyii/protected/views/mail/main_tpl.phpに一緒に送信され$dataます。$user

于 2015-02-01T15:21:42.483 に答える