我在cakePHP中有一个模型:
class PagesTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
$this->belongsTo('Pagecats');
$this->belongsToMany('Users');
}
和另一个模型PagecatsTable:
class PagecatsTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
}
它的桌子有两个列id
和category
如何在我的页面控制器的函数中获取category
?
在 PagesController 中,您是否需要页面及其关联的记录?如果是这样,您可以尝试以下提到的代码:
// PagesController.php
$data = $this->Pages->find()
->contain('Pagecats')
->all();
pr($data->toArray()); // Check if you're getting the desired result.