gpt4 book ai didi

php - CakePHP 从类所属的表中获取数据

转载 作者:行者123 更新时间:2023-11-29 21:05:26 25 4
gpt4 key购买 nike

我在 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');
}

它的表有两个列idcategory

如何在 PagesController 的函数中获取类别

最佳答案

在您的 PagesController 中,您想要页面及其关联记录吗?如果是这样,您可以尝试下面提到的代码:

// PagesController.php

$data = $this->Pages->find()
->contain('Pagecats')
->all();

pr($data->toArray()); // Check if you're getting the desired result.

关于php - CakePHP 从类所属的表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36855846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com