rest api expand, url params

This commit is contained in:
Kavalar 2024-10-07 11:54:10 +03:00
parent 04da662275
commit c7e113e325
2 changed files with 8 additions and 5 deletions

View File

@ -119,11 +119,11 @@ class Request
/** /**
* Возвращает GET - параметр. * Возвращает GET - параметр.
* @param string $param Параметр. * @param string|null $param Параметр.
* @param mixed $defaultValue Значение если, параметр не передан. * @param mixed|null $defaultValue Значение если, параметр не передан.
* @return mixed * @return mixed
*/ */
public function get($param = null, $defaultValue = null): mixed public function get(string $param = null, mixed $defaultValue = null): mixed
{ {
if (is_null($param)) { if (is_null($param)) {
return $_GET; return $_GET;

View File

@ -36,9 +36,12 @@ class RestController
#[NoReturn] public function actionView($id): void #[NoReturn] public function actionView($id): void
{ {
$expand = $this->expand(); $expand = $this->expand();
$request = new Request();
$expandParams = explode( ",", $request->get('expand') ?? "");
$model = $this->model->where("id", $id)->first(); $model = $this->model->where("id", $id)->first();
if ($expand){ $finalExpand = array_intersect($expandParams, $expand);
$model->load($expand); if ($finalExpand){
$model->load($finalExpand);
} }
$res = []; $res = [];
if ($model){ if ($model){