1
// 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 表中与上述条件匹配的第一个条目。我怎样才能让它返回整个类别列表?

4

2 回答 2

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;
于 2014-12-23T13:15:49.613 回答
0

您需要使用whileforeach循环填充。

$categories = $this->app['db']->fetchAssoc($query, $map);

foreach($categories as $category) {
   $result[] = $category;
}
$response = $this->app->json($result);
echo $response;
return $response;
于 2014-12-23T13:03:45.607 回答