質問編集履歴

1

Controllerのソースを追加

2022/04/06 10:41

投稿

haksen
haksen

スコア23

test CHANGED
File without changes
test CHANGED
@@ -28,3 +28,114 @@
28
28
  こちらはエラーは表示されませんでした。
29
29
 
30
30
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-04-05/5b08bb75-d2fe-48dd-9a67-66ac2a9a7154.jpeg)
31
+
32
+
33
+ ```PHP
34
+ コード
35
+ <?php
36
+ declare(strict_types=1);
37
+
38
+ namespace App\Controller;
39
+
40
+ /**
41
+ * PurchaseOrders Controller
42
+ *
43
+ * @property \App\Model\Table\PurchaseOrdersTable $PurchaseOrders
44
+ * @method \App\Model\Entity\PurchaseOrder[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
45
+ */
46
+ class PurchaseOrdersController extends AppController
47
+ {
48
+ /**
49
+ * Index method
50
+ *
51
+ * @return \Cake\Http\Response|null|void Renders view
52
+ */
53
+ public function index()
54
+ {
55
+ $purchaseOrders = $this->paginate($this->PurchaseOrders);
56
+
57
+ $this->set(compact('purchaseOrders'));
58
+ }
59
+
60
+ /**
61
+ * View method
62
+ *
63
+ * @param string|null $id Purchase Order id.
64
+ * @return \Cake\Http\Response|null|void Renders view
65
+ * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
66
+ */
67
+ public function view($id = null)
68
+ {
69
+ $purchaseOrder = $this->PurchaseOrders->get($id, [
70
+ 'contain' => [],
71
+ ]);
72
+
73
+ $this->set(compact('purchaseOrder'));
74
+ }
75
+
76
+ /**
77
+ * Add method
78
+ *
79
+ * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
80
+ */
81
+ public function add()
82
+ {
83
+ $purchaseOrder = $this->PurchaseOrders->newEmptyEntity();
84
+ if ($this->request->is('post')) {
85
+ $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData());
86
+ if ($this->PurchaseOrders->save($purchaseOrder)) {
87
+ $this->Flash->success(__('The purchase order has been saved.'));
88
+
89
+ return $this->redirect(['action' => 'index']);
90
+ }
91
+ $this->Flash->error(__('The purchase order could not be saved. Please, try again.'));
92
+ }
93
+ $this->set(compact('purchaseOrder'));
94
+ }
95
+
96
+ /**
97
+ * Edit method
98
+ *
99
+ * @param string|null $id Purchase Order id.
100
+ * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
101
+ * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
102
+ */
103
+ public function edit($id = null)
104
+ {
105
+ $purchaseOrder = $this->PurchaseOrders->get($id, [
106
+ 'contain' => [],
107
+ ]);
108
+ if ($this->request->is(['patch', 'post', 'put'])) {
109
+ $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData());
110
+ if ($this->PurchaseOrders->save($purchaseOrder)) {
111
+ $this->Flash->success(__('The purchase order has been saved.'));
112
+
113
+ return $this->redirect(['action' => 'index']);
114
+ }
115
+ $this->Flash->error(__('The purchase order could not be saved. Please, try again.'));
116
+ }
117
+ $this->set(compact('purchaseOrder'));
118
+ }
119
+
120
+ /**
121
+ * Delete method
122
+ *
123
+ * @param string|null $id Purchase Order id.
124
+ * @return \Cake\Http\Response|null|void Redirects to index.
125
+ * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
126
+ */
127
+ public function delete($id = null)
128
+ {
129
+ $this->request->allowMethod(['post', 'delete']);
130
+ $purchaseOrder = $this->PurchaseOrders->get($id);
131
+ if ($this->PurchaseOrders->delete($purchaseOrder)) {
132
+ $this->Flash->success(__('The purchase order has been deleted.'));
133
+ } else {
134
+ $this->Flash->error(__('The purchase order could not be deleted. Please, try again.'));
135
+ }
136
+
137
+ return $this->redirect(['action' => 'index']);
138
+ }
139
+ }
140
+ ```
141
+