/** * Update Email Templates * @return mixed */ public function actionEmails($id = null) { $id = $id == null ? 1 : $id; $model = $id == 0 ? new EmailTemplates() : EmailTemplates::findOne($id); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { Yii::$app->session->setFlash('success', $model->isNewRecord ? 'Created new template!' : 'Template Successfully Updated!'); // form inputs are valid, do something here $model->save(); } } return $this->render('emailtemplates', ['model' => $model]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = EmailTemplates::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'created_date' => $this->created_date, 'modified_by' => $this->modified_by, 'modified_date' => $this->modified_date]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'sender_options', $this->sender_options])->andFilterWhere(['like', 'sender', $this->sender])->andFilterWhere(['like', 'contents', $this->contents])->andFilterWhere(['like', 'signature_options', $this->signature_options])->andFilterWhere(['like', 'signature', $this->signature])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'footer', $this->footer]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getEmailTemplate() { return $this->hasOne(EmailTemplates::className(), ['id' => 'email_template_id']); }
public function getTemplates() { return yii\helpers\ArrayHelper::map(EmailTemplates::find()->all(), 'id', 'title'); }
/** * Send email, replacing predefined model content with given $params * @param string $to * @param string $template * @param array $params */ public function sendMail($to, $template_id, $params = []) { $template = \app\models\EmailTemplates::findOne($template_id); Yii::$app->mailer->compose('@app/mail/templates/content', ['body' => $template->body, 'params' => $params])->setFrom(['*****@*****.**' => 'Kid Crossing'])->setTo($to)->setSubject($template->subject)->send(); }
/** * Finds the EmailTemplates model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return EmailTemplates the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = EmailTemplates::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }