Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. $requete = $this->EmployesFormations->find('all')->where(['EmployesFormations.employe_id' => $idEmploye])->andWhere(['EmployesFormations.formation_id' => $idFormation])->first();
  2. $id = $requete->id;
  3. $employesFormation = $this->EmployesFormations->get($id, [
  4. 'contain' => []
  5. ]);
  6. if ($this->request->is(['patch', 'post', 'put'])) {
  7. $employesFormation = $this->EmployesFormations->patchEntity($employesFormation, $this->request->getData());
  8. $this->gererChamps($employesFormation);
  9. if ($this->EmployesFormations->save($employesFormation)) {
  10. $this->Flash->success(__('The employes formation has been saved.'));
  11.  
  12. return $this->redirect(['controller' => 'Employes', 'action' => 'view', $employesFormation->employe_id]);
  13. }
  14. $this->Flash->error(__('The employes formation could not be saved. Please, try again.'));
  15. }
  16. $employesformation = $this->EmployesFormations->newEntity();
  17. if ($this->request->is('post')) {
  18. if (!empty($this->request->data['name']['name'])) {
  19. $employesformationName = $this->request->data['name']['name'];
  20. $uploadPath = 'Files/';
  21. $uploadFile = $uploadPath . $employesformationName;
  22. if (move_uploaded_file($this->request->data['name']['tmp_name'], 'file/' . $uploadFile)) {
  23. $employesformation = $this->EmployesFormations->patchEntity($employesformation, $this->request->getData());
  24. $employesformation->name = $employesformationName;
  25. $employesformation->path = $uploadPath;
  26. //debug($file); die();
  27. if ($this->Formations->save($employesformation)) {
  28. $this->Flash->success(__('File has been uploaded and inserted successfully.'));
  29. } else {
  30. $this->Flash->error(__('Unable to upload file, please try again.'));
  31. }
  32. } else {
  33. $this->Flash->error(__('Unable to upload file, please try again.'));
  34. }
  35. }
  36. }
  37.  
  38. $employes = $this->EmployesFormations->Employes->find('list', ['limit' => 200]);
  39. $formations = $this->EmployesFormations->Formations->find('list', ['limit' => 200]);
  40. $this->set(compact('employesFormation', 'employes', 'formations'));
  41. $this->set('_serialize', ['employesFormation']);
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement