V
V
vladislav9972021-08-17 17:19:22
symfony
vladislav997, 2021-08-17 17:19:22

Where to add code once so that it works on a specific namespace for all controllers and their methods?

Such a question, there is a project on symphony, there is a directory in Dashboard controllers with App\Controller\Dashboard namespaces. For all controllers and their methods, you need to add the following code everywhere, which will be supplemented over time:

if($bot->getUser() != $this->getUser()) {
    throw $this->createNotFoundException('Access is denied')
}

Pushing all this into each method is not a very good idea, how can this be done in a normal way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2021-08-17
@sl0

Write your subsriber to kernel.controller .
There you already check for the necessary condition by namespace and change the controller as you like.

D
Deniev, 2021-08-30
@deniev

But creating a service with your code in a method, and calling it in the necessary methods is not an option?
At the very least, you won't have to change the code everywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question