CRUDlex\ControllerProvider::renderFile PHP Method

renderFile() public method

The controller for the "render file" action.
public renderFile ( Silex\Application $app, string $entity, string $id, string $field ) : Response
$app Silex\Application the Silex application
$entity string the current entity
$id string the instance id
$field string the field of the file to render of the instance
return Symfony\Component\HttpFoundation\Response the rendered file
    public function renderFile(Application $app, $entity, $id, $field)
    {
        $crudData = $app['crud']->getData($entity);
        $instance = $crudData->get($id);
        $definition = $crudData->getDefinition();
        if (!$instance || $definition->getType($field) != 'file' || !$instance->get($field)) {
            return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.instanceNotFound'));
        }
        return $crudData->renderFile($instance, $entity, $field);
    }