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

Related tags

Frameworks spm
Overview

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.

  • This is open source, feel free to contribute.
  • For small to mid sized projects.
  • No need to use composer.
  • No dependencies.
  • No need to configure web server.
  • Easy to deploy alongside other SPM projects on same server.
  • Easy to work with database.

Supports:

  1. PHP 5.3.1
  2. MYSQL
  3. MSSQL

Getting Started

  1. Download or clone the repo.
  2. Configure your database to app/Libraries/Database.php.
  3. Rename the root folder with your project name.
  4. Now you can create Controllers,Views and Models.

Routing

Creating routes is easy in SPM.

Open index.php.

Add your new route inside the switch statement.

Page not found "; break; }">
//index.php
switch($path){
    case "home"://route name
        new Home();//your controller
        break;
    default:
        echo "

Page not found

"
; break; }

To get data from POST request, add parameter to your controller function

//index.php
case "post"://route name
    Home::samplePost($_POST);//add parameter to get POST data
    break;

To get data from GET request, add parameter to your controller function

//index.php
case "get"://route name
    Home::sampleGet($_GET);//add parameter to get GET data
    break;

Controllers

Controllers responds to hyperlinks,form actions and url inputs.

  • Controllers are stored in app/Controller
  • Controllers class name must be the same as the file name.
  • Controllers extends app/Libraries/Controller.php

Lets create the function for the "post" route in Home controller.

public static function samplePost($post_data){
    //now you can get values from POST request
    //sample: $username = $post_data["username"];
}

And for our "get" route.

public static function sampleGet($get_data){
    //now you can get values from GET request
    //sample: $id = $get_data["user_id"];
}

Views

Views shows information to the user.

  • Views are stored in app/Views
  • Use snake case for naming views (sample: main_page.php)
  • You can create subfolders to organize your view files.

Let's use our view for Home controller(home route)

view("home"); $this->view("section/footer");">
$this->view("section/header");
$this->view("home");
$this->view("section/footer");

You can pass data to view. (Must be an associative array)

"Simple MVC Framework", "sub_header" => "Just what you need!"]; $this->view("section/header"); $this->view("home",$data); $this->view("section/footer");">
$data = ["header" => "Simple MVC Framework",
        "sub_header" => "Just what you need!"];
$this->view("section/header");
$this->view("home",$data);
$this->view("section/footer");

Keys from the array will be converted into variables that you can use in the views

">
//Views/home.php
<div class="full-screen column center">
    <h1 class="text-banner center-text"> <?= $header ?> h1>
    <h1 class="text-header"> <?= $sub_header ?> h1>
div>

Models

Models are used for CRUD(Create,Update,Delete) operations and SPM made that easy.

  • SPM currently supports Transactional Databases (MySql and MsSql).
  • Models are stored in app/Model
  • Model class names must be same as the file name.
  • Model class names must be PascalCase and have Model at the end(sample: HomeModel)
  • Model extends app/Libraries/Model.php

Initialize our model

When we don't place parameter, our model will use the default database.

//app/Controller/Home.php
$home_model = new HomeModel();

Use other database that is configured in app/Libraries/Database.php

//app/Controller/Home.php
$home_model = new HomeModel("ms");

We can also use other database even it is not declared in Database.php

//app/Controller/Home.php
$home_model = new HomeModel(null,$host,$user,$pass,$dbname,$driver(mysq;/mssql));

Select single item

getItem($query);">
//returns object and false on error
$query = "SELECT * FROM table WHERE id = 1";
$item = $home_model->getItem($query);

Select multiple items

getItems($query); //Cast each item to object for easier coding. foreach($items as $item){ $item = (object)$item; }">
//returns array and false on error
$query = "SELECT * FROM table";
$items = $home_model->getItems($query);

//Cast each item to object for easier coding.
foreach($items as $item){
  $item = (object)$item;
}

To INSERT,UPDATE or DELETE data

exec($query);">
//returns boolean
$query = "INSERT FROM table VALUES('1','Juan Dela Cruz')";
$result = $home_model->exec($query);

We can use parepared statement.

$value]; $item = $home_model->getItem("SELECT * FROM table WHERE id = :id",$params); $delete = $home_model->exec("DELETE FROM table WHERE id = :id",$params); $params = ["id"=>$value,"name"=>$name]; $update = $home_model->("UPDATE table SET name=:name WHERE id = :id",$params);">
$params = ["id" => $value];
$item = $home_model->getItem("SELECT * FROM table WHERE id = :id",$params);
$delete = $home_model->exec("DELETE FROM table WHERE id = :id",$params);

$params = ["id"=>$value,"name"=>$name];
$update = $home_model->("UPDATE table SET name=:name WHERE id = :id",$params);

Start Transaction

$home_model->startTrans();

Commit

$home_model->commit();

Rollback

$home_model->rollback();

Everytime we use our Model functions and it fails, we can get the error

$home_model->getError();

We can also see what is the database driver we are currently using.

$home_model->getDriver();

And we can also get the last inserted id

$home_model->lastId();
You might also like...
Minimal PHP MVC Framework that is eternally broken.

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

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

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.

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

Slim Framework skeleton application with MVC Schema

Slim Framework skeleton application with MVC Schema

A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire.
A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire.

Malzahar A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire. Re

Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight-PHP-Framework-For-APIs. Simple PHP framework that helps you quickly understand and write simple APIs. Installation Use the package manager

Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight PHP Framework For Web and APIs PHP framework that helps you write quickly simple but powerful web apps and APIs Installation Use the packa

Bootcamp project based on PHP-MVC using MySQL database.
Bootcamp project based on PHP-MVC using MySQL database.

Up-Stream This is the implementation of a full website based on PHP MVC. Using MySql database to create a website. And Bootstrap4 for front-end. Start

Releases(v1.2.0)
Owner
Van Hudson Galvoso
Software Developer
Van Hudson Galvoso
Quite possibly the smallest MVC framework you'll ever use.

Swiftlet Swiftlet is quite possibly the smallest MVC framework you'll ever use. And it's swift. Licensed under the MIT license. Buzzword compliance ✔

Elbert Alias 431 Feb 22, 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 (-.-) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ |-| █▄─▄▄─█▄─██─▄█─▄▄▄▄█─▄▄▄▄█▄─█─▄█─▄▄▄─██▀▄─██─▄

MasihGhaznavi 7 Jun 29, 2022
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

Mohammad Maleki 2 Sep 4, 2021
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

Luis Mendez 7 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

Anton 1 Dec 21, 2021
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

Etorojah Okon 14 Jun 10, 2022
💡 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

null 3 Nov 17, 2021
A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own...

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:/

Maniruzzaman Akash 8 Aug 8, 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

Amiranbari 6 Jul 9, 2022
This repository include my own PHP MVC Framework

PHP OWN MVC FRAMEWORK Kendimi geliştirmek ve modern PHP Framework'lerinin işleyişini kavram amacıyla inşa ettiğim profesyonele yakın PHP MVC Framework

Yılmaz Kadan 9 Jul 28, 2022