Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $requete = $this->EmployesFormations->find('all')->where(['EmployesFormations.employe_id' => $idEmploye])->andWhere(['EmployesFormations.formation_id' => $idFormation])->first();
- $id = $requete->id;
- $employesFormation = $this->EmployesFormations->get($id, [
- 'contain' => []
- ]);
- if ($this->request->is(['patch', 'post', 'put'])) {
- $employesFormation = $this->EmployesFormations->patchEntity($employesFormation, $this->request->getData());
- $this->gererChamps($employesFormation);
- if ($this->EmployesFormations->save($employesFormation)) {
- $this->Flash->success(__('The employes formation has been saved.'));
- return $this->redirect(['controller' => 'Employes', 'action' => 'view', $employesFormation->employe_id]);
- }
- $this->Flash->error(__('The employes formation could not be saved. Please, try again.'));
- }
- $employesformation = $this->EmployesFormations->newEntity();
- if ($this->request->is('post')) {
- if (!empty($this->request->data['name']['name'])) {
- $employesformationName = $this->request->data['name']['name'];
- $uploadPath = 'Files/';
- $uploadFile = $uploadPath . $employesformationName;
- if (move_uploaded_file($this->request->data['name']['tmp_name'], 'file/' . $uploadFile)) {
- $employesformation = $this->EmployesFormations->patchEntity($employesformation, $this->request->getData());
- $employesformation->name = $employesformationName;
- $employesformation->path = $uploadPath;
- //debug($file); die();
- if ($this->Formations->save($employesformation)) {
- $this->Flash->success(__('File has been uploaded and inserted successfully.'));
- } else {
- $this->Flash->error(__('Unable to upload file, please try again.'));
- }
- } else {
- $this->Flash->error(__('Unable to upload file, please try again.'));
- }
- }
- }
- $employes = $this->EmployesFormations->Employes->find('list', ['limit' => 200]);
- $formations = $this->EmployesFormations->Formations->find('list', ['limit' => 200]);
- $this->set(compact('employesFormation', 'employes', 'formations'));
- $this->set('_serialize', ['employesFormation']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement