Skip to content

A lightweight, docker ready Model View Controller (MVC) design pattern template using PHP 8.4 (Apache).

License

Notifications You must be signed in to change notification settings

boekemeyer/MVC-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MVC Template: A Lightweight PHP 8.4 MVC Framework

MVC Template PHP 8.4 GitHub Releases

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.

Table of Contents

  1. Features
  2. Getting Started
  3. Installation
  4. Directory Structure
  5. Usage
  6. Routing
  7. CSRF Protection
  8. Autoloading
  9. Docker Setup
  10. Contributing
  11. License
  12. Releases

Features

  • 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

Getting Started

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.

Installation

  1. Clone the Repository: Use Git to clone the repository to your local machine.

    git clone https://github.com/boekemeyer/MVC-Template.git
  2. Navigate to the Directory: Change into the project directory.

    cd MVC-Template
  3. 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.

  4. Set Up Docker: If you want to use Docker, follow the Docker setup instructions below.

Directory Structure

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.

Usage

To start using the MVC Template, follow these steps:

  1. Access the Public Directory: Your application will be served from the public directory. Make sure your web server points to this directory.

  2. Open Your Browser: Navigate to http://localhost (or your configured domain) to see the default welcome page.

  3. Modify as Needed: You can start adding your controllers, models, and views to build your application.

Routing

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.

CSRF Protection

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 . '">';

Autoloading

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.

Docker Setup

To set up your application with Docker, follow these steps:

  1. Install Docker: Make sure you have Docker and Docker Compose installed on your machine.

  2. Run Docker Compose: In the root of your project, run:

    docker-compose up -d
  3. Access the Application: Open your browser and go to http://localhost:8080 to view your application running in a Docker container.

  4. Stop the Containers: When you're done, you can stop the containers with:

    docker-compose down

Contributing

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.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Releases

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.