我想做什么:
我有一个像这样的数据库: 表格文章,标签,用户,类别
加入:
到目前为止我的查询:
private function findAllArticleRelatedStuff() {
$query = $articles->find();
$query->innerJoinWith('Tags', function ($q) {
$q->innerJoinWith('Users');
$q->innerJoinWith('Categories');
return $q;
});
$query->select(['Articles.articlename', 'Tags.tagname', 'Users.username', 'Categories.categoriename']);
return $query;
}
我想选择articlesname,tagsname,usersname,categoriesname并首先打印它(在视图中,已经通过set()完成了它)。
foreach($query as $article) {
debug($article->articlename); // works fine
foreach($article as $tag) {
debug($tag->tagname); // no output, no error
// other foreach loops or something...
}
}
我想我在这里犯了一个愚蠢的错误。
你可以给我一个关于创建这些值的数组的建议吗?我以为我在CakePHP中读到了一些数组方法。
编辑:(找到解决方案) 我没有正确地读出数据:
foreach($query as $article) {
debug($article->articlenamename);
debug($article->_matchingData["Tags"]["tagname"]);
}
答案 0 :(得分:0)
尝试调试($ article-> tag-> tagname);