I've setup my controller like this:
my_controller:
path: '/controller/{id}'
defaults:
_controller: '\Drupal\Mymodule\Controller\MyController::Render'
_title_callback: '\Drupal\Mymodule\Controller\MyController::getTitle'
requirements:
permission: 'access content'
Now, in my MyController.php I need to load an entity object (for which {id} is the id). Unfortunately, it seems I need to load my object twice. First, in my getTitle function because this is called first. Then again in my Render() function, which is called afterwards.
When I try to save the entity to my class as $this->entity It gets lost when the Render() function gets called. I tried to load via a constructor or create function, but these do not have access to the {id} slug in a proper manner.
What's the good practice way to make sure I need to load my entity object once for both functions?