Skip to content

Lightweight PHP MVC Framework with DataTables Server-Side Processing, Bootstrap 4 UI, and comprehensive user management system

License

elightsys/PHP-MVC-03

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PHP MVC Framework with DataTables Server-Side Processing

A lightweight, modern PHP MVC (Model-View-Controller) framework with integrated DataTables server-side processing, Bootstrap 4 UI, and comprehensive user management system.

PHP Version License Bootstrap DataTables

πŸš€ Features

  • MVC Architecture: Clean separation of concerns with Model-View-Controller pattern
  • Server-Side DataTables: Efficient handling of large datasets with AJAX pagination, sorting, and filtering
  • User Authentication: Complete user management system with role-based access control
  • Bootstrap 4: Modern, responsive UI components
  • Security Features:
    • HTTPS detection (proxy/load balancer compatible)
    • SQL injection protection
    • CSRF token validation
    • Password hashing
  • Database Integration: PDO-based database abstraction layer
  • Export Functionality: Export data to CSV, Excel, PDF, and Print
  • Real-time Updates: Auto-refresh DataTables with AJAX
  • Session Management: Secure user session handling

πŸ“‹ Requirements

  • PHP >= 7.4 (PHP 8.0+ recommended)
  • MySQL >= 5.7 or MariaDB >= 10.2
  • Apache/Nginx web server with mod_rewrite enabled
  • Composer (optional, for dependency management)

πŸ› οΈ Installation

1. Clone the Repository

git clone https://github.com/elightsys/PHP-MVC-03.git
cd PHP-MVC-03

2. Configure Database

Import the database schema:

mysql -u your_username -p your_database_name < mysql.sql

3. Configure Application

Copy the example configuration file and update it with your settings:

cp app/config/config.php.example app/config/config.php

Edit app/config/config.php and update the following:

// Database credentials
define('__DB_HOST__', 'localhost');
define('__DB_USER__', 'your_db_username');
define('__DB_PASS__', 'your_db_password');
define('__DB_NAME__', 'your_db_name');

// Generate a unique security key
define('__UNIQID__', md5(uniqid(rand(), true)));

4. Set Permissions

chmod -R 755 public/
chmod -R 777 storage/logs/ storage/cache/

5. Configure Web Server

Apache (.htaccess)

The .htaccess file is already included. Make sure mod_rewrite is enabled:

sudo a2enmod rewrite
sudo service apache2 restart

Nginx

Add this to your server block:

location / {
	try_files $uri $uri/ /public/index.php?$query_string;
}

location ~ \.php$ {
	include snippets/fastcgi-php.conf;
	fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
}

6. Access Your Application

Navigate to: http://your-domain.com/public/

Default login credentials (change immediately after first login):

  • Email: admin@example.com
  • Password: admin123

πŸ“ Project Structure

PHP-MVC-03/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ config.php.example    # Configuration template
β”‚   β”‚   └── config.php            # Your config (git-ignored)
β”‚   β”œβ”€β”€ controllers/              # Application controllers
β”‚   β”‚   β”œβ”€β”€ Pages.php
β”‚   β”‚   β”œβ”€β”€ Users.php
β”‚   β”‚   └── Admin.php
β”‚   β”œβ”€β”€ models/                   # Data models
β”‚   β”‚   β”œβ”€β”€ SspModel.php
β”‚   β”‚   └── AdminModel.php
β”‚   β”œβ”€β”€ views/                    # View templates
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ admin/
β”‚   β”‚   └── _inc/
β”‚   β”œβ”€β”€ libraries/                # Core libraries
β”‚   β”‚   β”œβ”€β”€ Core.php
β”‚   β”‚   β”œβ”€β”€ Controller.php
β”‚   β”‚   β”œβ”€β”€ Database.php
β”‚   β”‚   └── Ssp.php
β”‚   β”œβ”€β”€ helpers/                  # Helper functions
β”‚   └── autoload.php             # Autoloader
β”œβ”€β”€ public/                       # Public web directory
β”‚   β”œβ”€β”€ index.php                # Front controller
β”‚   β”œβ”€β”€ assets/                  # CSS, JS, images
β”‚   └── uploads/                 # User uploads
β”œβ”€β”€ mysql.sql                    # Database schema
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .htaccess
β”œβ”€β”€ LICENSE
└── README.md

🎯 Usage

Basic Routing

Routes are automatically mapped to controllers:

http://your-domain.com/public/Pages/Users
							   ↓      ↓
						  Controller  Method

Creating a New Controller

<?php
class YourController extends Controller {
    
	public function index() {
		$data = [
			'title' => 'Your Page Title'
		];
		$this->view('your-view', $data);
	}
}

DataTables Server-Side Processing

The framework includes a powerful DataTables SSP (Server-Side Processing) implementation:

public function SspUsersDT() {
	if (isset($_POST['draw'])) {
		exit(self::$sspModel->sspUserDT($_POST));
	}
}

Database Queries

$this->db->query('SELECT * FROM users WHERE active = :active');
$this->db->bind(':active', 1);
$results = $this->db->resultSet();

πŸ” Security Features

HTTPS Detection

The framework automatically detects HTTPS connections, even behind proxies and load balancers:

// Checks multiple sources for HTTPS
- $_SERVER['HTTPS']
- $_SERVER['HTTP_X_FORWARDED_PROTO']
- $_SERVER['HTTP_X_FORWARDED_SSL']
- $_SERVER['SERVER_PORT']

SQL Injection Protection

All database queries use PDO prepared statements:

$this->db->query('SELECT * FROM users WHERE email = :email');
$this->db->bind(':email', $email);

CSRF Protection

Forms include CSRF tokens:

$timestamp = time();
$token = md5('unique_salt' . $timestamp);

πŸ“Š DataTables Features

  • Server-Side Processing: Handle millions of records efficiently
  • AJAX Pagination: Smooth, fast pagination without page reloads
  • Search & Filter: Real-time search across all columns
  • Sorting: Multi-column sorting
  • Export Options: CSV, Excel, PDF, Print
  • Responsive Design: Mobile-friendly tables
  • Auto-refresh: Configurable auto-refresh interval

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact

πŸ› Known Issues

Please check the Issues page for known bugs and feature requests.

πŸ“š Documentation

For more detailed documentation, please visit the Wiki.


Note: This is a learning/demonstration project. For production use, consider additional security measures, comprehensive testing, and regular updates.

About

Lightweight PHP MVC Framework with DataTables Server-Side Processing, Bootstrap 4 UI, and comprehensive user management system

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages