php - MVC - A place for common functions?Get the solution ↓↓↓
I tend to think of traditional
MVC like this:
A controller is my business logic to implement my product.
A model is the code to represent data.
A view is what represents my product.
Under this paradigm,
what represents my product is what an end-user sees.
So if it's a UX component, it's part of the view.
In this way, it's pretty easy to figure out how to use it:
- You could
use path/to/notifications.phpand then
$notifications = new Notifications();where
notifications.phpis a class facilitating messages like you reference.
- You could
extends Notificationson your view (or even a base view!) so that ANY view you instantiate immediately has access to your notifications class.
- You could (though probably shouldn't)
require_once( 'path/to/notifications.php' );and then the class or functions therein would be available. Again, you probably shouldn't do it this way
The bottom line is this:
- Place your old procedural code in a well organized class. It might be named something like
Notificationsif that's what the code does. The important thing is to organize well, name well, and do not try to force too much code into one thing.
- Use that class in your code. You can explicitly use it's namespace and
newan instance of it, or you can extend it to bring it along as the parent class of your view.
Share solution ↓
Link To Answer People are also looking for solutions of the problem: the metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.