public function actionList() { $mailsQuery = Mail::find()->orderBy('created_at ASC'); foreach ($mailsQuery->each() as $mail) { /** @var Mail $mail */ $this->stdout("#{$mail->id} - {$mail->status}\n"); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Mail::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'receivers_provider', $this->receivers_provider])->andFilterWhere(['like', 'receivers_provider_data', $this->receivers_provider_data])->andFilterWhere(['like', 'from', $this->from])->andFilterWhere(['like', 'from_name', $this->from_name])->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'body_html', $this->body_html])->andFilterWhere(['like', 'boxy_text', $this->boxy_text])->andFilterWhere(['between', 'created_at', Yii::$app->formatter->asDate($this->created_at, 'YYYY-MM-d 00:00:00'), Yii::$app->formatter->asDate($this->created_at, 'YYYY-MM-d 23:59:59')]); return $dataProvider; }
/** * Finds the Mail model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Mail the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Mail::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }