CakePHPで作成したアプリケーションで表示したページの上部に
以下のようなエラーが表示されているのですが、原因がわからず困っています。
Notice (1024): Undefined property: PurchaseOrdersController::$PurchaseOrders in C:\xampp\htdocs\test\src\Controller\PurchaseOrdersController.php on line 21 [CORE\src\Controller\Controller.php, line 329]
環境
PHP 8.1.2
CakePHP 4.3.7
mySQL 8.0.28
Apache/2.4.52 (Win64)
手順
1)mysqlでテーブル定義
テーブル:purchase_order
テスト用に1件データを作成
2)CakePHP/bakeでスケルトン作成
bin\cake bake all purchase_orders
3)ブラウザで該当ページを表示
indexとして表示するレコードの一覧は正しく表示されているので
スケルトンの内容に問題無いように思います。
なぜエラーとして表示されているのか、
どうすれば解消できるのか教えていただけませんか。
試したこと
同じ構造を持つテーブル(orders)を作成して同様にスケルトンを作成したのですが
こちらはエラーは表示されませんでした。
PHP
1コード 2<?php 3declare(strict_types=1); 4 5namespace App\Controller; 6 7/** 8 * PurchaseOrders Controller 9 * 10 * @property \App\Model\Table\PurchaseOrdersTable $PurchaseOrders 11 * @method \App\Model\Entity\PurchaseOrder[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) 12 */ 13class PurchaseOrdersController extends AppController 14{ 15 /** 16 * Index method 17 * 18 * @return \Cake\Http\Response|null|void Renders view 19 */ 20 public function index() 21 { 22 $purchaseOrders = $this->paginate($this->PurchaseOrders); 23 24 $this->set(compact('purchaseOrders')); 25 } 26 27 /** 28 * View method 29 * 30 * @param string|null $id Purchase Order id. 31 * @return \Cake\Http\Response|null|void Renders view 32 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. 33 */ 34 public function view($id = null) 35 { 36 $purchaseOrder = $this->PurchaseOrders->get($id, [ 37 'contain' => [], 38 ]); 39 40 $this->set(compact('purchaseOrder')); 41 } 42 43 /** 44 * Add method 45 * 46 * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. 47 */ 48 public function add() 49 { 50 $purchaseOrder = $this->PurchaseOrders->newEmptyEntity(); 51 if ($this->request->is('post')) { 52 $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData()); 53 if ($this->PurchaseOrders->save($purchaseOrder)) { 54 $this->Flash->success(__('The purchase order has been saved.')); 55 56 return $this->redirect(['action' => 'index']); 57 } 58 $this->Flash->error(__('The purchase order could not be saved. Please, try again.')); 59 } 60 $this->set(compact('purchaseOrder')); 61 } 62 63 /** 64 * Edit method 65 * 66 * @param string|null $id Purchase Order id. 67 * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. 68 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. 69 */ 70 public function edit($id = null) 71 { 72 $purchaseOrder = $this->PurchaseOrders->get($id, [ 73 'contain' => [], 74 ]); 75 if ($this->request->is(['patch', 'post', 'put'])) { 76 $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData()); 77 if ($this->PurchaseOrders->save($purchaseOrder)) { 78 $this->Flash->success(__('The purchase order has been saved.')); 79 80 return $this->redirect(['action' => 'index']); 81 } 82 $this->Flash->error(__('The purchase order could not be saved. Please, try again.')); 83 } 84 $this->set(compact('purchaseOrder')); 85 } 86 87 /** 88 * Delete method 89 * 90 * @param string|null $id Purchase Order id. 91 * @return \Cake\Http\Response|null|void Redirects to index. 92 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. 93 */ 94 public function delete($id = null) 95 { 96 $this->request->allowMethod(['post', 'delete']); 97 $purchaseOrder = $this->PurchaseOrders->get($id); 98 if ($this->PurchaseOrders->delete($purchaseOrder)) { 99 $this->Flash->success(__('The purchase order has been deleted.')); 100 } else { 101 $this->Flash->error(__('The purchase order could not be deleted. Please, try again.')); 102 } 103 104 return $this->redirect(['action' => 'index']); 105 } 106}
回答1件
あなたの回答
tips
プレビュー