I'm creating a RESTful API with Phalcon.
I want to get some data from "Shop" table by IDs.
PHP code:
$app->post('/api/shops/search', function () use ($app) {
$ids_shop = $app->request->getJsonRawBody();
$ids = array();
foreach($ids_shop as $id){
$ids[] = $id->id_shop;
}
$ids_str = implode(",", $ids);
$shops = getShopsData($ids_str, $app);
return $shops;
});
function getShopsData($ids_shop, $app) {
$phql = "SELECT * FROM Shops WHERE Shops.id IN ( :ids: )";
$shops = $app->modelsManager->executeQuery($phql, array(
'ids' => $ids_shop
));
return $shops;
}
Test:
curl -i -X POST -d '[{"id_shop":1},{"id_shop":2}]' http://localhost/sample/api/shops/search
However I can get only one data whose id is 1. And I also tried it:
curl -i -X POST -d '[{"id_shop":2},{"id_shop":1}]' http://localhost/sample/api/shops/search
This returns one data whose id is 2.
Why cannot I get multiple data? My log says $ids_str = "1,2", so I think phql query might be correct...