📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

Full Php Mvc Oop Project (complete Structure)

I’ve created a complete working MVC OOP PHP project for you in the canvas 👉

This is a basic but real structure you can run and extend.


🚀 How to Run

  1. Create folder structure:
project/
app/
controllers/
models/
views/
core/
public/
  1. Move code into proper files (I kept it in one file for simplicity — you should split it)
  2. Run using:
  • XAMPP / WAMP → localhost/project/public
  • Or PHP built-in server:
php -S localhost:8000

⚠️ Important Improvements (Next Step)

Right now it’s basic, but for real production you should:

🔐 Add Database (MySQL)

  • Use PDO
  • Store users in DB (not array)

🧠 Add Features

  • Sessions (login system)
  • Middleware (auth check)
  • Validation
  • Error handling

📦 Use Autoloading

spl_autoload_register(function($class){
require_once \"../app/$class.php\";
});
<?php
// =============================
// SIMPLE MVC OOP PHP PROJECT
// =============================

// --------- FOLDER STRUCTURE ---------
// /project
//   /app
//     /controllers
//     /models
//     /views
//   /core
//   /config
//   public/index.php

// =============================
// CORE: Router
// =============================
class Router {
    public function route() {
        $url = $_GET['url'] ?? 'home/index';
        $url = explode('/', $url);

        $controllerName = ucfirst($url[0]) . 'Controller';
        $method = $url[1] ?? 'index';

        require_once "app/controllers/$controllerName.php";
        $controller = new $controllerName();

        call_user_func([$controller, $method]);
    }
}

// =============================
// CORE: Controller
// =============================
class Controller {
    public function model($model) {
        require_once "app/models/$model.php";
        return new $model();
    }

    public function view($view, $data = []) {
        require_once "app/views/$view.php";
    }
}

// =============================
// MODEL: User
// =============================
class User {
    private $users = [];

    public function register($name, $password) {
        $this->users[$name] = password_hash($password, PASSWORD_DEFAULT);
    }

    public function login($name, $password) {
        if (isset($this->users[$name]) && password_verify($password, $this->users[$name])) {
            return true;
        }
        return false;
    }
}

// =============================
// CONTROLLER: Home
// =============================
class HomeController extends Controller {
    public function index() {
        $this->view('home');
    }
}

// =============================
// CONTROLLER: Auth
// =============================
class AuthController extends Controller {
    private $user;

    public function __construct() {
        $this->user = new User();
    }

    public function register() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $this->user->register($_POST['name'], $_POST['password']);
            echo "Registered Successfully";
        }
        $this->view('register');
    }

    public function login() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            if ($this->user->login($_POST['name'], $_POST['password'])) {
                echo "Login Success";
            } else {
                echo "Login Failed";
            }
        }
        $this->view('login');
    }
}

// =============================
// VIEW: home.php
// =============================
?>
<h1>Welcome to MVC App</h1>
<a href="?url=auth/register">Register</a>
<a href="?url=auth/login">Login</a>

<?php
// =============================
// VIEW: register.php
// =============================
?>
<form method="POST">
    <input type="text" name="name" placeholder="Name">
    <input type="password" name="password" placeholder="Password">
    <button type="submit">Register</button>
</form>

<?php
// =============================
// VIEW: login.php
// =============================
?>
<form method="POST">
    <input type="text" name="name" placeholder="Name">
    <input type="password" name="password" placeholder="Password">
    <button type="submit">Login</button>
</form>

<?php
// =============================
// PUBLIC: index.php (ENTRY POINT)
// =============================
require_once '../core/Router.php';
require_once '../core/Controller.php';

$router = new Router();
$router->route();


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes