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
コード <?php declare(strict_types=1); namespace App\Controller; /** * PurchaseOrders Controller * * @property \App\Model\Table\PurchaseOrdersTable $PurchaseOrders * @method \App\Model\Entity\PurchaseOrder[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) */ class PurchaseOrdersController extends AppController { /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ public function index() { $purchaseOrders = $this->paginate($this->PurchaseOrders); $this->set(compact('purchaseOrders')); } /** * View method * * @param string|null $id Purchase Order id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { $purchaseOrder = $this->PurchaseOrders->get($id, [ 'contain' => [], ]); $this->set(compact('purchaseOrder')); } /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ public function add() { $purchaseOrder = $this->PurchaseOrders->newEmptyEntity(); if ($this->request->is('post')) { $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData()); if ($this->PurchaseOrders->save($purchaseOrder)) { $this->Flash->success(__('The purchase order has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The purchase order could not be saved. Please, try again.')); } $this->set(compact('purchaseOrder')); } /** * Edit method * * @param string|null $id Purchase Order id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function edit($id = null) { $purchaseOrder = $this->PurchaseOrders->get($id, [ 'contain' => [], ]); if ($this->request->is(['patch', 'post', 'put'])) { $purchaseOrder = $this->PurchaseOrders->patchEntity($purchaseOrder, $this->request->getData()); if ($this->PurchaseOrders->save($purchaseOrder)) { $this->Flash->success(__('The purchase order has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The purchase order could not be saved. Please, try again.')); } $this->set(compact('purchaseOrder')); } /** * Delete method * * @param string|null $id Purchase Order id. * @return \Cake\Http\Response|null|void Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $purchaseOrder = $this->PurchaseOrders->get($id); if ($this->PurchaseOrders->delete($purchaseOrder)) { $this->Flash->success(__('The purchase order has been deleted.')); } else { $this->Flash->error(__('The purchase order could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); } }
まだ回答がついていません
会員登録して回答してみよう