// Get all categories
$query = "SELECT name FROM bolt_taxonomy WHERE taxonomytype = :taxonomytype AND contenttype = :contenttype";
$map = array(
':taxonomytype' => 'categories',
':contenttype' => 'news',
);
$categories = $this->app['db']->fetchAssoc($query, $map);
$response = $this->app->json(array('categories' => $categories));
return $response;
返回:
{
"categories": {
"name": "life"
}
}
这只是与bolt_taxonomy表上的上述条件匹配的第一个条目。如何让它返回整个类别列表?
答案 0 :(得分:1)
现在使用fetchAll
:
// Get the category
$query = "SELECT name FROM bolt_taxonomy WHERE taxonomytype = 'categories' AND contenttype = 'news'";
$categories = $this->app['db']->query($query);
$result = $categories->fetchAll();
$response = $this->app->json(array('categories' => $result));
return $response;
答案 1 :(得分:0)
您需要使用while
或foreach
循环填充。
$categories = $this->app['db']->fetchAssoc($query, $map);
foreach($categories as $category) {
$result[] = $category;
}
$response = $this->app->json($result);
echo $response;
return $response;