PeterBubresko Posted October 21 Share Posted October 21 I am trying to read me up on PHP again, and now I am trying to understand what a framework is, and what a controller is, and what a controller does. Okay, first thing first. I have understood or misunderstood that a framework is a platform or an application developers are using to program or set up a site or a script like VS Code or Dream Weaver etc. If I read about a framework on another website a framework is like a template. Can someone please tell me what it is. There is also this with controls. Is this a script that will operate in several places or be called on several times? To save time, this is put into a separate file that is called on from different places multiple times. What is the right thing here, and am I completely out of my mind? I am confused about this. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 22 Share Posted October 22 2 hours ago, PeterBubresko said: I have understood or misunderstood that a framework is a platform or an application developers are using to program or set up a site or a script like VS Code or Dream Weaver etc. Misunderstood. Frameworks are a bunch of code that other people wrote to do stuff. Using them saves you the time of having to write your own bunch of code to do stuff. They do so much stuff that the intention is you take what they provide as a foundation and then add what you want. There's also libraries, which are a bunch of code that other people wrote to do stuff that saves you the time of having to write your own code to do stuff, but they're much smaller in scope than frameworks. They're basically about solving small individual problems, so using libraries means you don't have to solve those same problems yourself and you can focus on more important issues. There is overlap between frameworks and libraries. The distinction is in how they get used: are you taking a bunch of stuff and adding more, or are you using stuff to create other separate stuff? VS Code and Dreamweaver (if anyone still uses that) are "integrated development environments", but everybody just calls them IDEs. IDEs are glorified text editors, in that they let you type stuff into a text file just like any simple text editor does, but IDEs also have tons of features dedicated to dealing with code and so are much nicer to use than text editors. Like they can be aware of language syntax nuances and tell you when you wrote something wrong, while text editors might be able to do a little bit of that but would care more about checking your spelling. 2 hours ago, PeterBubresko said: If I read about a framework on another website a framework is like a template. Can someone please tell me what it is. I don't like "template" as a metaphor. A template is about taking something and supplying a few bits here and there and you're done. You go to some blog creator website (coughwordpress) and they'll give you a template for a site: you set a name, colors, images, whatever, but all you're doing is customizing the same basic thing that everybody else is using. This forum is basically a template because we installed Invision Power Board and customized it a bunch. A framework is about you having a starting point for actually building something - not just customizing. You write code to do things, you implement features, you make decisions about how things work, and so on. Making a complicated website involves many different things, and frameworks have a lot of that designed for you so you don't have to make it all yourself. 2 hours ago, PeterBubresko said: There is also this with controls. Is this a script that will operate in several places or be called on several times? To save time, this is put into a separate file that is called on from different places multiple times. What is the right thing here, and am I completely out of my mind? I am confused about this. Where are you seeing "controls"? That typically means things like text boxes and buttons and links, like right now I'm typing into a "textarea" control that has a bunch of formatting button controls at the top and a "submit" button control below it. But people don't normally use the word "control" much these days. I think maybe you shouldn't worry much about what a control is. It's such a generic term that it doesn't really say much. "Text box" and "button" and "link" are specific types of controls, and talking about those is much easier (but also kinda off-topic from what we're talking about now). 1 Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 22 Share Posted October 22 (edited) I like to think of a framework as literally that - a frame you use to build your project on. So instead of having to write your database connection, display, and interconnecting code for each project you can concentrate on the actual functional logic for that specific project. Use the framework-provided database connection to get the data, write the templates to display the data (but don't worry about actually rendering the templates), and auto load the extra files you'll need to process the data the user sends to you, adjust and amend it as necessary, and send that data to the template that will render it. Basically, frameworks at their heart do the boring and repetitive stuff for you. Beyond that I think there's been a slight misunderstanding when you're talking about "controls". Most modern frameworks (Laravel, CodeIgniter, and CakePHP most notably) are based on the MVC design pattern wherein there are Models, Views, and Controllers. Controllers basically ingest the data the user submits, retrieves any additional data your system needs from the Models (and/or saves data via the Models), works on that data as necessary, and then sends that resulting data to be rendered in the View. So think of it like Models interact directly with the database, Views interact directly with the browser, and Controllers dictate the actual function of your system by interacting with the Models and Views. Edited October 22 by maxxd 1 Quote Link to comment Share on other sites More sharing options...
PeterBubresko Posted October 22 Author Share Posted October 22 Thank you both very much. These answers were very well explained. I Will come back to these topics. It was a lot to digest at once. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.