Welcome to the MVC Template repository! This project provides a lightweight, Docker-ready Model View Controller (MVC) design pattern template using PHP 8.4 with Apache. Whether you're a novice or an experienced developer, this template offers a straightforward way to build web applications.
- Features
- Getting Started
- Installation
- Directory Structure
- Usage
- Routing
- CSRF Protection
- Autoloading
- Docker Setup
- Contributing
- License
- Releases
- Lightweight and easy to use
- Built with PHP 8.4 and Apache
- Docker-ready for easy deployment
- CSRF protection built-in
- Simple routing system
- Supports autoloading for classes
- Clean directory structure for easy navigation
To get started with the MVC Template, you can download the latest release from the Releases section. Make sure to follow the installation instructions below.
-
Clone the Repository: Use Git to clone the repository to your local machine.
git clone https://github.com/boekemeyer/MVC-Template.git
-
Navigate to the Directory: Change into the project directory.
cd MVC-Template
-
Download the Latest Release: You can also directly download the latest release from the Releases section. Make sure to extract the files to your desired location.
-
Set Up Docker: If you want to use Docker, follow the Docker setup instructions below.
The directory structure is designed to be clean and intuitive. Here’s an overview:
MVC-Template/
├── app/
│ ├── controllers/
│ ├── models/
│ └── views/
├── config/
├── public/
│ └── index.php
├── vendor/
├── docker-compose.yml
└── README.md
- app/: Contains your application logic.
- controllers/: Handle user requests and responses.
- models/: Manage data and business logic.
- views/: Store your HTML templates.
- config/: Configuration files for your application.
- public/: Publicly accessible files. The
index.php
file is the entry point. - vendor/: Contains third-party libraries.
- docker-compose.yml: Docker configuration file.
To start using the MVC Template, follow these steps:
-
Access the Public Directory: Your application will be served from the
public
directory. Make sure your web server points to this directory. -
Open Your Browser: Navigate to
http://localhost
(or your configured domain) to see the default welcome page. -
Modify as Needed: You can start adding your controllers, models, and views to build your application.
The MVC Template includes a simple routing system. You can define routes in the public/index.php
file. Here’s an example:
$router->get('/', 'HomeController@index');
$router->get('/about', 'AboutController@index');
This will map the root URL to the index
method of the HomeController
and the /about
URL to the index
method of the AboutController
.
To protect your application from CSRF attacks, the MVC Template includes built-in CSRF protection. You can use the provided functions to generate and verify CSRF tokens in your forms.
Example:
// Generate CSRF token
$token = generateCsrfToken();
// Include token in your form
echo '<input type="hidden" name="csrf_token" value="' . $token . '">';
The template supports autoloading of classes. You can include your classes in the app/controllers
, app/models
, and app/views
directories without needing to manually include them. Just follow the PSR-4 standard for your class names and directory structure.
To set up your application with Docker, follow these steps:
-
Install Docker: Make sure you have Docker and Docker Compose installed on your machine.
-
Run Docker Compose: In the root of your project, run:
docker-compose up -d
-
Access the Application: Open your browser and go to
http://localhost:8080
to view your application running in a Docker container. -
Stop the Containers: When you're done, you can stop the containers with:
docker-compose down
We welcome contributions to the MVC Template! If you have suggestions or improvements, please fork the repository and submit a pull request. Make sure to follow the coding standards and include tests for any new features.
This project is licensed under the MIT License. See the LICENSE file for more details.
For the latest updates and releases, check the Releases section. Download the latest version, extract the files, and execute as needed.
Thank you for checking out the MVC Template! We hope it helps you build your next web application with ease.