Answer the question
In order to leave comments, you need to log in
The correct structure of the application?
Hey! I have a main application page (landing page) where many parts change on ajax requests. In order not to pollute its controller, I'm thinking of making an additional controller, which will have functions for issuing new data via ajax. For example actionLoadModal() and so on. Will it be right?
I thought to do this, because I need to load a lot of views. Thanks in advance!
Answer the question
In order to leave comments, you need to log in
In this case, you will get a crazy controller that is responsible for all ajax requests. It's good if you have 3-4 methods there. And if they eventually become 20 or 100? Nobody needs such a controller.
If we go this way, then create an ajax folder and put different controllers there. ajax/BlogController
. If necessary, you can make another nesting ajax/blog/PostsController
. What if ajax is replaced by api? api/blogs/posts
So we got a simple api. Why invent something new) Api can be made as simple as your ajax controller, only it will not be inherited from the web controller and you do not need to constantly reformat the data.
And if there are a lot of such ajax requests - maybe you should think about a js framework on the frontend. Making a framework out of yii2 js is such an undertaking.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question