r/PHPhelp • u/foolsdata • Jan 22 '24
Solved MVC framework
Anyone know of sites that teach a basic concept of an MVC framework and how to design one. I want to make one from scratch based on 8.x.x version. I know there are dozens of frameworks already made but I enjoy learning how to make my own. The last one I made was based on 7.x.x but some of the php libraries have been changed and my code produces errors now
1
u/foolsdata Jan 24 '24
The following function used by PHP 8.0.27 is going to be depreciated in newer versions of PHP.
call_user_func_array();
I'm using it as
call_user_func_array([$this->currentController,$this->currentMethod],$this->params);
But when I upgrade my PHP version to 8.2 it throws an depreciation notice.
Thus the reason for looking for a better way of creating my own MVC framework.
4
3
u/equilni Jan 22 '24
The last one I made was based on 7.x.x but some of the php libraries have been changed and my code produces errors now
What's wrong with fixing the errors and updating the code base?
1
u/MateusAzevedo Jan 22 '24
This Symfony tutorial will teach how write a custom framework using Symfony components. This other one may also be use useful.
But I don't know why you can't just fix your current one to be compatible with PHP 8.
1
u/_steveCollins Jan 23 '24
I like watching long form videos of people coding, and while I don't always agree with his choices, this guy has a lot of videos and a series in particular on building a framework.
1
u/crkunferman Feb 09 '24 edited Feb 09 '24
I see that this is solved but I had a conversation with a GPT that gave me a very simple framework to start with. If you'd like the entire conversation please advise as there is additional information. Here is the basic setup for an API:
my_api_project/
├── index.php # The main entry point for the API.
├── .htaccess # For URL rewriting and redirecting requests to index.php.
├── config/
│ ├── database.php # Database connection settings.
├── models/
│ ├── Item.php # Model representing an item, with properties and methods for database interactions.
├── controllers/
│ ├── ItemsController.php # Controller for handling item-related request logic.
├── routes/
│ ├── api.php # Defines API routes and maps them to controller methods.
├── utils/
│ ├── ResponseFormatter.php# Utility for formatting API responses.
└── public/
├── .htaccess # Additional .htaccess file for public directory, if needed.
└── index.php # Optionally, a forwarding script to the main index.php at root.
0
u/richardathome Jan 22 '24
This is pretty much it:
Model -> talks to the data store
View -> talks to the user
Controller -> talks to the Model and the View.
2
u/ryantxr Jan 22 '24
Laracasts has an entire video series where he walks you through building an MVC framework.