Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Daniel Corn
@cundd
You have a custom Handler right?
baggyownz
@baggyownz
yes
based on custom_rest handlder
Daniel Corn
@cundd
Do you already have the Route that you want to call?
baggyownz
@baggyownz
the TableField is not the uid
Daniel Corn
@cundd
Is TableField dynamic?
baggyownz
@baggyownz
no only a fix row from db table
Daniel Corn
@cundd
Alright. So it's what you registered in TypoScript
plugin.tx_rest.settings.paths {
CallTableField {
        path = CallTableField

        read = allow
        write = allow

        handlerClass = \Cundd\CustomRest\Rest\Handler

    }
}
no sorry. the link was the wrong line
baggyownz
@baggyownz
paths {
        CallTableField {
            path = CallTableField-*
            read = allow
            write = deny
            handlerClass = \VENDOR\ExtName\Rest\Handler
        }
    }
Daniel Corn
@cundd
now you would add something like this:
$router->add(
    Route::get(
        $request->getResourceType() . '/{slug}',
        function (RestRequestInterface $request, $identifier) {
            $repository = somehow_get_the_repository();

            $model = $repository->findByTheIdentifierThatSuitsYourRequirements($identifier);

            if (!$model) {
                return $this->responseFactory->createErrorResponse(
                    'The model was not found',
                    404,
                    $request
                );
            } else {
                return $model;
            }
        }
    )
);
baggyownz
@baggyownz
i try to get the repo
Daniel Corn
@cundd
You can use dependency injection
or $this->objectManager->get(YourCoolRepositoryClass::class) to test it
but DI is nicer
baggyownz
@baggyownz
okay
now i got "null" as response
Daniel Corn
@cundd
can you check if the route was called?
E.g. var_dump something
baggyownz
@baggyownz
i get the given identifier
Daniel Corn
@cundd
try return json_encode($model)
maybe you found something that could be improved in the extension
baggyownz
@baggyownz
{"message":"{}"}
Daniel Corn
@cundd
  if (!$model) {
                        return $this->responseFactory->createErrorResponse(
                            'The model was not found',
                            404,
                            $request
                        );
                    } else {
                        return $this->responseFactory->createSuccessResponse(
                            json_encode($model),
                            200,
                            $request
                        );
                    }
and implement JsonSerializable for your Model
then you should be fine
baggyownz
@baggyownz
oh man..
some other things damaged now..
i'll fix that first and then get back to you. thanks first of all
Daniel Corn
@cundd
oh thats not good :-S
baggyownz
@baggyownz
sooo..
first problem is fixed.
but the model is still empty
i looked at the query and that's ok
Daniel Corn
@cundd
Can you try it like this:
$extractor = $this->objectManager->get(\Cundd\Rest\DataProvider\ExtractorInterface::class);

return $this->responseFactory->createSuccessResponse(
    $extractor->extract($model),
    200,
    $request
);
baggyownz
@baggyownz
uhhh.. at first view it looks good
Daniel Corn
@cundd
my first suggestion was wrong too ;)
baggyownz
@baggyownz
:D
sometimes its tricky
Daniel Corn
@cundd
Good that it's already friday :D
baggyownz
@baggyownz
yep
baggyownz
@baggyownz
can i add also multiple parameters?
baggyownz
@baggyownz
or can i exclude fields in the result?
Daniel Corn
@cundd
you can still implement JsonSerializable and return only the public fields
and you can add additional parameters
you than have to customize the route
baggyownz
@baggyownz
aaah i got it
thanks
(public fields)
baggyownz
@baggyownz
thanks again and a nice weekend
Daniel Corn
@cundd
you too :)