控制器代码:控制器代码适用于雇主分页,但无法对 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.php
namespace 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.php
namespace App\Model\Entity;
use Cake\ORM\Entity;
class Spk extends Entity
{
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
<?php
// src/Model/Table/StoriesTable.php
namespace 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.php
namespace 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
倚天杖
千万里不及你