This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

zorogat5480
zorogat5480

Hello, I have a decent grasp on how things work in the backend, I developed a plugin, and I can see how the MVC pattern is identified in the backend. What for me is a bit blurred is the frontend side of things and what would be best practices for it.

Is it correct to assume that the Code Part of the frontend Pages are acting as controllers? Because the only other way I see to develop a bit of logic in the frontend is to develop a component.. but I don't need/want to develop a component for each single query or piece of logic that is in the frontend.. it seems a bit exaggerated.

So , here's my question: where do you actually develop your logic in the frontend? By logic I mean for example, saving data using Models according to Post variables, validated by some Rules etc... I hope my question is clear enough...

daftspunky
daftspunky

The code section of a page is really there as a way to implement PHP code in pages, since it is not readily available using Twig. It is designed for arbitrary coding, minimal code should be placed here, or ideally none at all, however it's up to you how you want to use it. All the features of components are available in the code section.

The Components act as Controllers, it allows you to have multiple Controllers on a single page cycle and this makes them more portable and reusable. Think of them as a cross between Web Components and Controllers, so they should be grouped by user interface controls. Again this is up to you how you want to use it. The traditional MVC controller approach would see you using 1 component per page, a single controller.

zorogat5480
zorogat5480

Ok, thank you daftspunk. My initial understanding was that the Page events (onStart etc) were mimicking the Android Activity class methods (on Create, onStart) but after your explanation that's not the case.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.