/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AttachedFiles::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(['request_id' => $this->request_id]); $query->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
/** * Finds the AttachedFiles model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $request_id * @param string $url * @return AttachedFiles the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($request_id, $url) { if (($model = AttachedFiles::findOne(['request_id' => $request_id, 'url' => $url])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function upload() { foreach ($this->requestFile as $file) { $this->fileNameAttached = uniqid() . '.' . $file->extension; $file->saveAs('files/' . $this->fileNameAttached); $attachedFiles = new AttachedFiles(); $attachedFiles->request_id = $this->id; $attachedFiles->url = $this->fileNameAttached; $attachedFiles->save(); } }
/** * @return \yii\db\ActiveQuery */ public function getAttachedFiles() { return $this->hasMany(AttachedFiles::className(), ['request_id' => 'id']); }