/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Email::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(['email_id' => $this->email_id, 'email_scholar_id' => $this->email_scholar_id]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Email::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Finds the Email model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Email the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Email::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { $model = new Email(); $model->email = 'test'; $model->save(); }
echo $form->field($model2, 'content')->textarea(['rows' => 6]); ?> <?php echo Html::submitButton($model2->isNewRecord ? 'Send Email' : 'Update', ['class' => $model2->isNewRecord ? 'btn btn-primary' : 'btn btn-primary']); ?> <br><br><h5><i>The explanation will be reviewed by the SM Foundation. <br>We will inform you for any updates regarding the case. Thank You! </i></h5> <?php ActiveForm::end(); ?> <?php $username = Yii::$app->user->identity->username; $users = User::find()->all(); $scholars = Scholar::find()->all(); $model2 = new Email(); foreach ($users as $user) { foreach ($scholars as $scholar) { if ($user->username == $username && $user->id == $scholar->scholar_user_id) { $model2->email_scholar_id = $scholar->scholar_id; $model2->subject = "Low/Fail Grade"; if ($model2->load(Yii::$app->request->post())) { $to = "*****@*****.**"; $subject = "Low/Fail Grade"; $body = $model2->content . "\nfrom:" . $scholar->scholar_contact_email . PHP_EOL; $headers = "from: root@localhost"; if (mail($to, $subject, $body, $headers)) { \Yii::$app->getSession()->setFlash('error', 'The message is delivered'); } else { \Yii::$app->getSession()->setFlash('error', 'Message failed'); }