Actually, this is one of the things that makes a web application such a challenge. The challenge is to decide where the components that make the application work should all lie and how they are composed. The on('click')
you mentioned is interface behavior handled strictly within the browser. Though, where was the HTML that holds that event “built” in the end? On the server or the client?
Let’s go a step higher. If you break the server down into its smallest roles, then I believe it only has two. One, it is the gateway to the data to show or manipulate through user interaction on a device (the real interface MMI). And the other, the server is the holder of the actual code needed to give the user the ability to interact.
Let’s concentrate on these two roles.
Frameworks like Symfony were originally built just before or during the start of the mobile paradigm shift we saw the past decade. So, they were built to serve “normal” web pages, which held both the code and the data and with the ability to be dynamic with both. This is all really cool stuff too.
Though again, these frameworks were created only at the start of the mobile paradigm shift. Now that we have this paradigm, developers want the client to do more and the server less. And still, it doesn’t matter. The code and data always originate from the/ a server. Think about this. Even an iOS or Android app must come from a server. And, in this scenario, the roles have been split between two servers. Apple and Google holding the code, and you as the app dev, you have a server holding the data.
So, where am I going with this?
I think, from a framework standpoint, we need to get away from the controller being the strong armed middle man and coordinator it currently is. We don’t necessarily have “pages” anymore, or rather, we are moving slowly but surely away from multiple web page applications. So, in that respect, we don’t need the page controller type of architecture we see in most frameworks. It ties our hands to that “old way” of composing the logic and thinking. All the “extra steps” of getting code and content together is still the norm. And, everything we do has to “fit” this methodology. Even worse, we even call it smart, if what we do works with it too, like when it also works for subrequests or REST APIs. Yippee, we made it fit!
If you will, we need a smarter dumb server, since the clients are getting smarter and smarter. And to me, that means the view needs to take over the role of the “getter” of data, no matter if it should bundle it in HTML or send out JSON or whatever else the client wants.
And, making this shift means, that would leave the controller with the role of only manipulating the model, as it was intended to do. Yes, it complicates the view and simplifies the controller. But, to change to be more proficient for a smart client/ dumb server paradigm, I think it makes sense. And yes…it is all theoretical. I wish I were a better programmer to make it all a reality faster to test.
But, let’s go with this line of logic. Why do we need to turn a GET into any “Action” in a controller, assuming we are follow the HTTP standard and the GET is used for the retrieval of a resource only? We know what is being requested. Why do we even need the controller? The view can be (and should be IMHO) responsible for pulling the required data from the model. And, it has all it needs to “figure out” what to do. The request.
Now, probably one of the more experienced devs will chime in and say, but you are going to have to push the logic you need from the router into the view. Well, let’s let the router route to the view on GETS. We only need the logic (or convention) of “is this a read or a write request”? Read, go to the view. Write, go to a controller. And, once the controller is done with its changes, go automatically back to the view. Since the model is already built and modified by the controller, the view only has to get the data and output it, and in accordance with what was requested. The format can be conventionalized. (Is that a real word? LOL! ) Putting the data in HTML is only one convention.
So, in this scenario, if there is a subtemplate, the view knows (is told prior/ during template creation) to also request the data it needs to send out that HTML and data too. No controller has any idea (nor should it) that the view needed this data.
I feel this more direct routing of GET requests is simpler for the smarter clients we are moving more and more towards. And again, I may be wrong too. I still need to find that out. I am just coming into this world of frameworks looking for solutions and going “WTF?”. Like, why do I need an additional bundle to do REST in Symfony? To me, REST is now the standard, and putting a page together with HTML is just a nice-to-have fallback, which I also question should even be needed in this day and age.
Needless to say, that “WTF” reaction could also be the same reaction from someone else, if ever my contemplations became a reality too. I don’t know. I am just a rambling idiot myself.
Scott