A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own...

Last update: Aug 2, 2022

PHPMVC

A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own...


How to Start

Clone this repo -

git clone https://github.com/ManiruzzamanAkash/phpmvc.git

Modify the .env file

Duplicate .env.example and create .env file for your own -

BASE_DIR=
APP_TITLE="Site Title"

DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_NAME=phpmvc
  1. BASE_DIR: The root directory of your project if you want to keep your project to any sub-directory of the domain, like devsenv.com/new-app. If no sub-directory is required, leave it empty.
  2. APP_TITLE: The title of your site.
  3. DB_HOST: The hostname of your database server, default : localhost.
  4. DB_PORT: The port of your database server, default: 3306
  5. DB_USER: The username of your database server, default: root.
  6. DB_PASSWORD: The password of your database server. default: empty.
  7. DB_NAME: The name of your database, default: phpmvc.

Extend: Add your own MVC

Route

Example 1: Add routes in route.php

<?php

use App\Base\Router;
use App\Controllers\WelcomeController;

Router::get('/', [WelcomeController::class, 'hello']);

Example 2: Closure function

use App\Base\Router;

Router::get('/', function() {
    return 'Hello World';
});

Router::get('/hello-another', function() {
    return views('welcome/hello');
});

Example 3: Portfolio Route

use App\Base\Router;
use App\Controllers\PortfoliosController;

Router::get('portfolios', [PortfoliosController::class, 'index']);

Model

We can create any model inside app\Models folder by extending base Model class.

Example 1: Create a TestModel class in app\Models\TestModel.php.

<?php

namespace App\Models;

use App\Base\Model;

class TestModel extends Model
{
   //
}

Example 2: Portfolio Model: in app\Models\Portfolio.php

<?php

namespace App\Models;

use App\Base\Model;

class Portfolio extends Model
{
    protected string $tableName = 'portfolios';

    public function get(): array|false
    {
        return $this->fetchAll("SELECT * FROM {$this->tableName}");
    }

    public function findById(int $id)
    {
    }
}

Controller

We can create any controller inside app\Controllers folder by extending base Controller class.

Example 1: TestsController in app\Controllers\TestsController.php

<?php

namespace App\Controllers;

use App\Base\Controller;

class TestsController extends Controller
{
    public function index()
    {
        //
    }
}

Example 2: PortfoliosController in app\Controllers\PortfoliosController.php

<?php

namespace App\Controllers;

use App\Base\Controller;
use App\Models\Portfolio;

class PortfoliosController extends Controller
{
    public function index()
    {
        $portfolio = new Portfolio();
        $portfolios = $portfolio->get();

        return views('portfolios/index.php', compact('portfolios'));
    }
}

Views

We can create any view file inside views folder.

Example 1: Simple view file: in views/index.php

<h2>Home Page</h2>

Example 2: View file with extending header and footer.

View Header:

in views/partials/header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo env('APP_TITLE'); ?></title>

    <!-- Load Styles -->
    <link rel="stylesheet" href="<?php echo assets('css/style.css'); ?>">
</head>
<body>
    <!-- Load Header Nav-->
    <?php views('/partials/nav.php'); ?>

    <!-- Content start -->
    <div class="main-content">
        <!-- Content will be loaded here. -->

View Footer:

in views/partials/footer.php

</div>
<!-- Script -->
<script src="<?php echo assets('js/base.js'); ?>"></script>
</body>
</html>

Portfolio main view by extending header and footer.

<?php views('/partials/header.php'); ?>

<h2>Portfolios</h2>
<?php foreach($portfolios as $portfolio): ?>
    <li><?php echo $portfolio['title']; ?></li>
<?php endforeach;?>

<?php views('/partials/footer.php'); ?>

Helper Methods

views()

You can load any view file inside views folder using this views() function.

// Index view file
views('index.php');

// Portfolio Views
views('portfolios/index.php');

// Pass additional data.
$name = 'Akash';
views('portfolios/index.php', compact('name'));

// Or pass multiple data.
$portfolios = [
    ['title' => 'Portfolio 1'],
    ['title' => 'Portfolio 2'],
];

views('portfolios/index.php', compact('portfolios'));

assets()

Assets will be loaded from assets folder. You load CSS, JS or images by calling assets method.

assets('css/style.css');
assets('js/base.js');

env()

Get environment variables by calling env method.

env('DB_NAME');

env('APP_TITLE');

url()

Create an url by the given path with this url() function.

// Home URL
url('/');

// Portfolios URL
url('portfolios');

Contributors

Name Github Email
Maniruzzaman Akash ManiruzzamanAkash [email protected]

New Contribution

You're welcomed to any open-source contribution under MIT licence.

Create a Pull Request at https://github.com/ManiruzzamanAkash/phpmvc/pulls

GitHub

https://github.com/ManiruzzamanAkash/phpmvc
You might also like...

A simple PHP MVC framework without extra files and codes that you don't need

Welcome to (SPM) Simple PHP MVC, just what you need! This is a simple PHP MVC framework without extra files and codes that you don't need.

Aug 4, 2022

a micro mvc framework for php

micro-mvc-php a micro mvc framework for php Config your Web url in .env . lifecycle All request proccess by index.php Autoload files include in bootst

Jul 9, 2022

The Hive is a simple php mvc framework

The Hive is a simple php mvc framework

Hive framework The Hive is a simple php mvc framework . Information Features : -MVC design -PDO connection -OOP system -Twig template -Very Fast, simp

Sep 4, 2021

Minimal PHP MVC Framework that is eternally broken.

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ██ ▄▄▄ █ ▄▄▀█ ▄▄██▄██ ▄▀██▄██ ▄▄▀█ ▄▄▀ ██ ███ █ ▄▄▀█▄▄▀██ ▄█ █ ██ ▄█ ▀▀ █ ██ ██ ▀▀▀ █▄▄▄▄█▄▄▄█▄▄▄█▄▄██▄▄▄█▄██▄█

Dec 16, 2021

A Slim PHP MVC framework built just for fun!

Aura Framework A Slim PHP MVC framework built just for fun! en: Note: This repository only contains the core code of the Aura framework. If you want t

Dec 16, 2021

PHP MVC Framework

You can select version on branch list. cmd composer install 0.1. Z Framework (V2.0.0) 0.2. Easiest, fastest PHP framework. (Simple) 0.3. Document 1.

Jul 10, 2022

A simle MVC framework implimentation using php

Vanilla-framwork A simle MVC framework implimentation using php , no additonal 3rd party are used (Vanilla Php); Email Support Configuration for email

Jul 10, 2022

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework. It is free, Open Source and is distributed under Free Public Lice

Apr 12, 2022

Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP. I've created a simple CRUD application to understand how it works. I used twig and I created a custom middleware to handle PUT, DELETE methods.

Feb 6, 2022
Related tags
TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

TrailLamp Introduction TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs. Installatio

Jun 10, 2022
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.

Woski is a simple fast PHP framework for the Realm The Project Installation Clone the repository $ composer create-project clintonnzedimma/woski myApp

Apr 13, 2022
A modern, ultra lightweight and rocket fast Content Management System

Redaxscript A modern, ultra lightweight and rocket fast Content Management System for SQLite, MSSQL, MySQL and PostgreSQL. Installation Clone the repo

Aug 10, 2022
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

Aug 14, 2022
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

Aug 3, 2022
a framework for WebDevelop based on the mvc structure. The name of this project for Fun because everyone can use it. Completely simple and powerful structure for all your projects

A_A (-.-) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ |-| █▄─▄▄─█▄─██─▄█─▄▄▄▄█─▄▄▄▄█▄─█─▄█─▄▄▄─██▀▄─██─▄

Jun 29, 2022
Symprowire is a PHP MVC Framework based and built on Symfony, using the ProcessWire CMS as DBAL and Service Provider.

Symprowire - PHP MVC Framework for ProcessWire 3.x Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Serv

Jan 16, 2022
FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Ruby on Rails.

FlyCubePHP FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Rub

Dec 21, 2021
💡 Mudrock is a MVC PHP framework, which was inspired by the Laravel and CodeIgniter frameworks.

?? Mudrock is a MVC PHP framework, which was inspired by the Laravel and CodeIgniter frameworks

Nov 17, 2021