控制器代碼:控制器代碼適用于雇主分頁,但無法對 Stories 控制器進行分頁。 public $paginate = [ 'Employers' => ['scope' => 'employer'], 'Stories' => ['scope' => 'story'] ]; public function index() { // Paginate property $this->loadComponent('Paginator'); // In a controller action $stories = $this->paginate($this->Stories, ['scope' => 'story']); $employers = $this->paginate($this->Employers, ['scope' => 'employer']); pr($stories); $this->set(compact('employers', 'stories')); }模型代碼:模型描述對于所有模型來說都是一樣的,但是理解模型定義不能用于故事模型,但是隨著我們對雇主表的模型定義的進展,它工作得很好。<?php// src/Model/Table/EmployersTable.phpnamespace App\Model\Table;use Cake\ORM\Table;class EmployersTable extends Table{ public function initialize(array $config): void { $this->addBehavior('Timestamp'); }}<?php// src/Model/Entity/Employer.phpnamespace App\Model\Entity;use Cake\ORM\Entity;class Spk extends Entity{ protected $_accessible = [ '*' => true, 'id' => false, 'slug' => false, ];}<?php// src/Model/Table/StoriesTable.phpnamespace App\Model\Table;use Cake\ORM\Table;class StoriesTable extends Table{ public function initialize(array $config): void { $this->addBehavior('Timestamp'); }}<?php// src/Model/Entity/Story.phpnamespace App\Model\Entity;use Cake\ORM\Entity;class Sty extends Entity{ protected $_accessible = [ '*' => true, 'id' => false, 'slug' => false, ];}當我通過加載頁面操作時,我一直在尋找錯誤,我面臨著雇主數據調用但故事數據無法加載的問題。建議開放查看期待您的回答。錯誤信息:Undefined property: EmployersController::$Stories in /Applications/MAMP/htdocs/sd/sd/src/Controller/EmployersController.php
2 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
當然有可能,該功能已明確記錄在案。該錯誤與分頁無關,它只是意味著您嘗試訪問的屬性 ( $this->Stories) 不存在。
控制器只有一個自動加載的默認模型,即根據約定與控制器名稱匹配的模型,因此在您EmployersController的Employers模型中。額外的模型需要手動加載:
$this->loadModel('Stories');
// ...
$stories = $this->paginate($this->Stories, ['scope' => 'story']);
- 2 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消