[英]CakePHP get data from a table that class belongs_to
我在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
如何在我的PagesController的函數中獲取category
?
在您的PagesController中,您是否需要頁面及其相關記錄? 如果是這樣,您可以嘗試下面提到的代碼:
// PagesController.php
$data = $this->Pages->find()
->contain('Pagecats')
->all();
pr($data->toArray()); // Check if you're getting the desired result.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.