Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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.');
     }
 }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttachedFiles()
 {
     return $this->hasMany(AttachedFiles::className(), ['request_id' => 'id']);
 }