php - Is it bad to inject controller class into a controller class? -


I have to try to follow the single responsibility principle, I view the presentation decided that I could be in another class. I already plan to use 5 dependencies to render the form. Therefore, the main controllers who have less dependencies in form injection are good.

I did not inject the controller class ever in the controller classes. What I usually do, I create a library

But now thinking - maybe a better controller will be in for an injection in a controller?

Tried to search for this, but did not find any examples but at the same time tried to create a controller with the constructor function and echo a string. Then inject this controller into another one. And the string is displayed.

So it means that it is possible to inject the controller in the controller, is it good? Or maybe it would be a necessity?

By default Laravel does not have a library folder which is also interesting, that the creators may assume that it is not needed.

Yes, it is bad controllers have not only the responsibility, but they have a different kind of class There are also only one task: A controller is a proxy between HTTP request and your application (model, repository, view). So basically it should get an HTTP request, get some data from your models and send it in a view.

Everything else should be done by your support class (model, repository, assistant, musician, etc.). ).

If you need to call other controller class, so maybe it's possible because you need ways to the controller should not be in the controller, as the controller works more than his job are doing.

This is one of my controllers:

  extends class connect bas controller {public function index () {$ connections = $ this- & gt; Execute (GetConnectionsCommand :: class); See Return: Creating ('connections.index') - & gt; With ('connection', $ connection); }}   

There is a lot going on behind the scenes of that GetConnectionsCommand to get information to show all the connections, and my controller has everything about it Do not know.

There are some subviews in that regard. Index ', but calling is a visible responsibility, my controller does not want to know that subview is required to present a specific view. I can see a master and some @if s can render all of these properly.

Returns to a controller data (a rendered view, by another class rendered) back to the reaction object (behind the scenes in Laravel), which is attributed to the person who effectively data Which will be back in your browser. So a controller is right in the middle of something, very little solicitation because it knows more about your business logic, and you think it's a talk for another controller. ' would be required . If you want you can think of it as MVP, but using this single MSP is to use single responsibility theory because it should be. But in this case the controller is not understood from the scene because there is no interface between them, so it is not actually MVP.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -