38 lines
647 B
PHP
38 lines
647 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
Flight::route('GET /v1/api/image/get/@id', function($id)
|
||
|
|
{
|
||
|
|
|
||
|
|
$model = new ImagesModel();
|
||
|
|
$result = $model->get($id);
|
||
|
|
$output = [];
|
||
|
|
if ($result)
|
||
|
|
{
|
||
|
|
$allow_fields = ['id', 'url', 'user_id', 'caption'];
|
||
|
|
|
||
|
|
foreach ($result as $key => &$value)
|
||
|
|
{
|
||
|
|
if (in_array($key, $allow_fields))
|
||
|
|
{
|
||
|
|
$output[$key] = $value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
echo json_encode([
|
||
|
|
'code' => 200,
|
||
|
|
'error' => false,
|
||
|
|
'model' => $output
|
||
|
|
]);
|
||
|
|
http_response_code(200);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
echo json_encode([
|
||
|
|
'code' => 404,
|
||
|
|
'error' => true
|
||
|
|
]);
|
||
|
|
http_response_code(404);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
});
|