开发者

CakePHP: Displayfield in associative model not working

开发者 https://www.devze.com 2023-03-24 01:06 出处:网络
My table Country has a Displayfield Country. Country is开发者_运维技巧 connected to the Users table through country_id. The displayfield works perfect in the User views.

My table Country has a Displayfield Country.

Country is开发者_运维技巧 connected to the Users table through country_id. The displayfield works perfect in the User views.

The User creates Posts and is connected with a foreign key user_id in the Posts table.

Problem: when I use $posts['User']['country_id'], I only can show the country ID itself and not the name. The Displayfield does not work in the associative model Posts.

How can I solve this? Thanks!


You need to set the recursive property to 2. For example:

$this->Post->recursive = 2;
$posts = $this->Post->find('all');
0

精彩评论

暂无评论...
验证码 换一张
取 消