MVC CRUD (Simple Project) - PHP-based CRUD application showcasing MVC architecture. Includes basic CRUD operations for managing products. Ideal for learning MVC principles. Organized, modular code structure.
MVC CRUD (Simple Project)
This is a simple MVC-based CRUD (Create, Read, Update, Delete) application built using PHP. It demonstrates the fundamental principles of the Model-View-Controller architectural pattern for web development. The project includes controllers for managing CRUD operations, models for interacting with the database, and views for rendering the user interface.
Features:
Create,read,update, anddeleteproducts.- Basic user interface for managing products.
MVCstructure for organized and modular code.
This project serves as a learning resource for understanding MVC architecture for absolute beginners and implementing basic CRUD functionality in PHP applications.
To run this project locally on your machine, follow these steps:
-
Clone the Repository:
git clone https://github.com/Adamo08/simple_crud_mvc.git
-
Navigate to the Project Directory:
cd simple_crud_mvc
-
Update the Hosts File:
- The hosts file is used by your operating system to map hostnames to IP addresses.
- Adding an entry to the hosts file is necessary to associate the custom domain
crud_mvc.localwith the loopback IP address127.0.0.1, allowing you to access your local server using this domain. - On Windows, the hosts file is located at
C:\Windows\System32\drivers\etc\hosts. - On Unix-based systems (e.g., Linux, macOS), it's typically located at
/etc/hosts. - Add the following line at the end of the hosts file, then save the changes:
127.0.0.1 crud_mvc.local
-
Configure the Virtual Host:
- A virtual host allows you to run multiple websites on the same server.
- Setting up a virtual host in your Apache configuration is necessary to serve your project files from a custom domain (
crud_mvc.local) instead of the defaultlocalhost. - Open your Apache configuration file (e.g.,
httpd-vhosts.conf), usually located inC:\xampp\apache\conf\extra\. - Add the following configuration to create a virtual host for your project:
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/MVC Examples/CRUD MVC/Public" ServerName crud_mvc.local </VirtualHost> - This configuration specifies that requests to
crud_mvc.localshould be served from thePublicdirectory of your project. - After making changes to the Apache configuration, don't forget to restart Apache to apply the changes.
-
Configure the Database:
- Create a new MySQL database.
- Navigate to
http://localhost/phpmyadmin/index.php - Then click
Add New DatabaseorNouvelle base de donnéeson the left side - Then select
importorimporter, and navigate tosimple_crud_mvc/App/Databaseand selectproducts.sql - Once the file is selected, scroll down and hit
import
-
Update Database Configuration:
- Open the
App/Config/config.phpfile. - Update the database configuration variables.
- In the 13th line
define("HOST", "localhost:4306"), change the host port to your own (by default, it's3306)
- Open the
-
You're ready to go!:
- Congratulations! You have successfully set up the MVC CRUD application.
- To access the application, open your web browser and type
crud_mvc.localin the address bar. - You should now be able to view the application and perform CRUD operations on products.
-
Note:
- Database Interaction: This project utilizes the PHP MySQLi Database Class for efficient database interactions. The class files are situated in the
App/Core/DBdirectory within your project. Ensure that the class files are readily accessible to your project. - For further insights and understanding of its functionality, you can explore the repository to delve into its workings.
- Database Interaction: This project utilizes the PHP MySQLi Database Class for efficient database interactions. The class files are situated in the
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or create a pull request.