SitesController.php
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Sites Controller
*
* @property \App\Model\Table\SitesTable $Sites
*/
class SitesController extends AppController
{
/**
* Index method
*
* @return \Cake\Network\Response|null
*/
public function index()
{
$sites = $this->paginate($this->Sites);
$this->set(compact('sites'));
$this->set('_serialize', ['sites']);
}
/**
* View method
*
* @param string|null $id Site id.
* @return \Cake\Network\Response|null
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$site = $this->Sites->get($id, [
'contain' => ['Materiels']
]);
$this->set('site', $site);
$this->set('_serialize', ['site']);
}
/**
* Add method
*
* @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$site = $this->Sites->newEntity();
if ($this->request->is('post')) {
$site = $this->Sites->patchEntity($site, $this->request->data);
if ($this->Sites->save($site)) {
$this->Flash->success(__('The site has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The site could not be saved. Please, try again.'));
}
}
$this->set(compact('site'));
$this->set('_serialize', ['site']);
}
/**
* Edit method
*
* @param string|null $id Site id.
* @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function edit($id = null)
{
$site = $this->Sites->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$site = $this->Sites->patchEntity($site, $this->request->data);
if ($this->Sites->save($site)) {
$this->Flash->success(__('The site has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The site could not be saved. Please, try again.'));
}
}
$this->set(compact('site'));
$this->set('_serialize', ['site']);
}
/**
* Delete method
*
* @param string|null $id Site id.
* @return \Cake\Network\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$site = $this->Sites->get($id);
if ($this->Sites->delete($site)) {
$this->Flash->success(__('The site has been deleted.'));
} else {
$this->Flash->error(__('The site could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}