Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
69 @duckfan77 mvc stands for model, view controller.
Basically for each page you are going to load at least 3 files (or more if you need multiple model or less if you don't need a model) and each file has its puprose
Controller->knows which data and views are currently needed to be rendered. Loads the correct models and runs the correct functions to get the needed data and passes it to the view.
Model->fetches data from various sources (like the database) and makes it usable for the controller/view
View->makes the html using the data it got from the controller

And no, you don't need to create 3 files for each page. The controller and model are classes and you usually group code together that is about the same thing. For example you might make a file called user_controller and use_model. Then both probably have functions like
login(),register(),update(),delete(),profile()
 

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
70 In Java, the preferred built-in GUI system (Swing) lumps the view and controller together. A JButton, for instance, generates MouseClick events when the user clicks on it (which is the controller's job), but also allows the text shown on it to be updated (which the view would normally handle). All of that happens in the same class, as it would be difficult to do otherwise.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
71 Well, this is HTML generation, if you need to respond to a button you need to write JS code to do so. This code can either stay totally client side or it can make a new request to the server using what is known as an ajax call.
As a result, I often have 2 big splits in my routes. One for normal requests and one for ajax requests. Both then split off in many more depending on what I need.
Code:
browser->users->login
         profile
         register
     
     game->   loadBattle
         loadDeck
         
ajax->   users->   loadProfileData
         //some other stuff here
     game->   discardCard
         playCard
         addCardToDeck
And this is only a very small sample of all the routes that my game needs.
Currently I have about 58 different routes and there are still a lot more needed.
 

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
72 Ok, so when a user of your website wants to do basically anything, their browser sends a request (of any type) to the server, which must then be parsed and sent to the part of the program best equipped to deal with it. In determining where to send the request, you have a decision tree, and each path through the tree you call a "route".

Is that reasonably accurate?
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
73 yes. (each program being a function inside an object called a controller which then works together with a model and a view to give the correct output )
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
75 I like how this thing went from "let me write these simple functions so I can rewrite my game more easily as php is kind of bad at it" to "I now want it to be stand alone and not be depended on lapis any more and just be an awesome framework."

Also, I didn't build it on top of sailor (which is also an awesome framework) because it doesn't work with a route file. And due to how it loads stuff in I wouldn't be able to split the controller folder into the biggest groups like I like to do
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
77 you mean the game? Or the framework?
Game, well...depending on how it all goes that might take a while. Especially as I think we need to move on to other projects at school.