I have this controller:
/**
* {@inheritdoc}
*
* @Route("entity/{domain_host}")
* @ParamConverter("entity", class="AppBundle:Entity", options={
* "repository_method" = "findOneByDomainHost",
* "mapping": {"domain_host": "domainHost"},
* "map_method_signature" = true
* })
*/
class EntityController extends Controller
{
...
}
Thus, a similar URL http://example.com/entity/another-example.comcorresponds to the action, and the corresponding object is another-example.comhydrated and passed to the controller.
Now this object also has an identifier.
I would like to intercept the url, for example http://example.com/entity/12345, and redirect it to http://example.com/entity/another-example.com.
For this, I created another method in EntityController:
class EntityController extends Controller
{
public function redirectIdToDomainAction(Request $request)
{
die(dump($request));
}
}
And in mine routing.yml, AT THE BEGINNING OF THE FILE:
entity_id_to_domain:
path: /entity/{id}
defaults: { _controller: AppBundle:Entity:redirectIdToDomain }
requirements:
id: ^[^.]*$
methods: [GET]
In practice, the action redirectIdToDomainis called if the placeholder does not contain a point (the point is discriminant: if the placeholder has a point, the domain is transferred, if there is no point, then probably the placeholder represents Entity by uts ID, and I should redirect).
, , EntityController @ParamConverter, - , , a AppBundle:Entity object not found..
, @ParamConverter , ? , , redirectToIdAction Not found?