Cakephp - 如何使用关联模型从其他模型获取数据?
Cakephp - How to get data from other model using associated model?
如何加入两个模型 table 以根据 user_id 获取用户名?
likesTable.php - id | post_id | user_id
1 5 23
postTable.php - id | like_id | user_id |内容
5 1 23 Hello
userTable.php - id | user_name |
23 sample_name
后控制器
$this->paginate = [
'contain' => ['Users', 'Likes'],
];
$posts = $this->paginate($this->posts);
蛋糕 PHP 视图中的变量
'likes' => object(App\Model\Entity\likes) id:4 {
'id' => (int) 1
'post_id' => (int) 5
'user_id' => (int) 23 ***I want to get user name from this ID***
在容器中添加喜欢的用户 (Likes.Users)
$this->paginate = [
'contain' => ['Users', 'Likes.Users'],
];
如何加入两个模型 table 以根据 user_id 获取用户名?
likesTable.php - id | post_id | user_id
1 5 23
postTable.php - id | like_id | user_id |内容
5 1 23 Hello
userTable.php - id | user_name |
23 sample_name
后控制器
$this->paginate = [
'contain' => ['Users', 'Likes'],
];
$posts = $this->paginate($this->posts);
蛋糕 PHP 视图中的变量
'likes' => object(App\Model\Entity\likes) id:4 {
'id' => (int) 1
'post_id' => (int) 5
'user_id' => (int) 23 ***I want to get user name from this ID***
在容器中添加喜欢的用户 (Likes.Users)
$this->paginate = [
'contain' => ['Users', 'Likes.Users'],
];