M7 Flashcards
What is MVC and how it works?
Model View Controller - An architectural design pattern.
An HTTP request comes in for the homepage. The URL goes through something called routing that chooses a controller. The controller decides which model and view is needed, combines them, and returns the result to the user.
Describe the Model in MVC?
The data layer - a class that actually interacts with the database
Describe the View in MVC?
Output. - What the user actually sees.
The HTML/JSON/XML that is sent back.
What is the Controller in MVC?
The thing that sticks a model and a view together
Why MVC?
Seperation of concerns - Any individual layer can be swapped out at any time for a different implementation.
What is a PHP framework? Give a couple of examples.
A framework enforces an architectural pattern.
Laravel is the most popular PHP framework by far.
Symfony is one of the oldest. Actually, it’s not really a framework, but lots of libraries.
Drupal is a cross between a CMS and framework.
Slim is a minimalist framework.
Why use PHP framework?
Consistency
It’s designed and tested by other software developers, so you know it’s a solid foundation.
Transferable skills
A framework makes it easier to implement MVC, as doing MVC without a framework is actually quite hard. The framework does a lot of it for us.
Routing
What are small/micro frameworks?
Small number of files.
Lightweight - doesn’t require huge amounts of memory and/or processing power.
Doesn’t do much for you - does not provide facilities such as authentication and object-relational mapping.
If what you’re building is small now, but hopefully bigger in future, then an enterprise framework would be best.
What are large/enterprise frameworks?
Large number of files.
Heavyweight - needs powerful servers.
Does lots for you. Contains lots of ‘magic’.
if you aren’t using all the features then you have lots of unneeded files and processing.
What is an oppinionated framework? Pros and cons?
A framework, by definition, makes some assumptions about architecture, best practices, and conventions.
An opinionated framework will only give you one way to do things.
Opinionated framework:
Pro - Forced consistency
Con - Less flexibility
What is routing and its benefits?
Routing allows you to map a URL to a particular piece of code, but there doesn’t need to be any relationship between the URL and the file(s) being used.
Benefits:
Your file structure does not have to match the URL structure.
URLs can be dynamic.
A bit of added security. Not much, but it does hide the file structure to a degree.
What folder structure does Slim framework have?
public - Static content like CSS and JS.
app - The application code required to run Slim.
src - Our custom application code.
templates - .phtml files, also known as views.
tests - Unit tests.
vendor - Third party stuff like phpunit.
How does routing work in Slim ?
Slim 4 provides a routing system that takes a web request and returns a response depending on the application logic in a request handler.
$app->get(‘/’, callableClass)
What is a Templating Engine?
A template engine enables you to use static template files in your application.
At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client.
What is Dependency Injection?
Dependency injection is a design pattern.
It is passing a dependency to an object rather than instantiating it inside the object.
Can be done by passing the dependency as a parameter to a constructor or a setter.