Relative Content

Tag Archive for requestmiddlewarecakephp-4.x

Cakephp 4 how to get request (or controller name) in Application.php?

I need to be able to get the request or just the controller name in the middleware so I can do some conditional logic. I am trying to modify the middleware() function in Application.php. Based on the controller called in the request, I will add or not add certain other middleware. All the examples I can find talk about creating a custom middleware and adding it to the middleware queue. I tried this but I am unable to pass variables back to the main middleware() function. Is it possible to get the request/controller in the main middleware() without having to create a customer middleware? If that is not possible, how do I pass a variable back to middleware() from a custom middleware so that I can conditionally add or not add other middleware in the middleware queue?