PHPackages                             momik/simple-mvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. momik/simple-mvc

AbandonedArchivedLibrary[Framework](/categories/framework)

momik/simple-mvc
================

v1.5-stable(3y ago)011[1 PRs](https://github.com/PG-Momik/MVC-Framework/pulls)PHP

Since Sep 26Pushed 3y ago2 watchersCompare

[ Source](https://github.com/PG-Momik/MVC-Framework)[ Packagist](https://packagist.org/packages/momik/simple-mvc)[ RSS](/packages/momik-simple-mvc/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (8)Dependencies (1)Versions (11)Used By (0)

Introduction
============

[](#introduction)

A simple PHP MVC framework built from scratch.

Pre-requisites
==============

[](#pre-requisites)

- ### XAMPP or Manual created environment with:

    [](#xampp-or-manual--created-environment-with)

    - #### PHP 8.0+

        [](#php-80)

        ```
          sudo apt update
          sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
          sudo add-apt-repository ppa:ondrej/php
          sudo apt install php8.0 -y
          sudo apt install php8.0-cli php8.0-common php8.0-mbstring -y

        ```
    - #### MySQL DB

        [](#mysql-db)

        ```
          sudo apt update
          sudo apt install mysql-server

        ```
    - #### Apache2

        [](#apache2)

        ```
          sudo apt update
          sudo apt install apache2

        ```
- ### Composer

    [](#composer)

    ```
      sudo apt update
      cd ~
      curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

    ```

    ```
      HASH=`curl -sS https://composer.github.io/installer.sig`
      php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

    ```

    ```
      sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

    ```

    ```
      composer

    ```

Installation
============

[](#installation)

- ### Create app using

    [](#create-app-using)

    ```
      composer create-project momik/simplemvc example-app

    ```
- ### Navigate to ' public '

    [](#navigate-to--public-)

    ```
      cd example-app
      cd public

    ```
- ### Serve app at port:8080

    [](#serve-app-at-port8080)

    ```
      php -S localhost:8080

    ```

Getting Started
===============

[](#getting-started)

- DATABASE
    --------

    [](#database)

    Edit the `.env ` file to configure database.

    - Set database name in `DB_DSN = ......dbname ='test_db'`
    - Set user in `DB_USER = root`
    - Set password in `DB_PASSWORD = password`
- Migration
    ---------

    [](#migration)

    Run `migrations.php` to initialize database ```
    php migrations.php

    ```

    You can manipulate database and tables by adding scripts in ' `migrations` ' directory.

    - There is no strict naming convention for migration scripts.
    - Migration scripts need to be a class with classname = filename.
    - Migration class need to have `up()` and `down()` method.
    - Run `migrations.php` so that changes take effect.

Documentation
=============

[](#documentation)

- Entry point
    -----------

    [](#entry-point)

    - The `public/index.php` is the entry point for the application.
    - `public/index.php` determines how HTTP requests are handled.

    ### Syntax:

    [](#syntax)

    ```
    Router::METHOD('/url', callback);

    ```

    ### Example:

    [](#example)

    Anonymous functions:

    ```
    Router::GET('/test', function(){
      //some code here
      return "This is test."
    });

    ```

    ```
    Router::POST('/test', function(){
     //some code here
     return "This is test."
    });

    ```

    Controller functions:

    ```
    Router::GET('/login', [LoginController::class, 'index']);

    ```

    ```
    Router::POST('/login', [LoginController::class, 'login']);

    ```
- Controllers
    -----------

    [](#controllers)

    - Write Controllers in `controllers` directory.
    - `YourController` must extend `Controller`.
    - Controllers must contain property: `public array $params[]`
    - Members/elements of this array property can be accessed as separate variable in respective view.
    - Example. ```
        $this->params['message'] = "This is message";  //in controller

            // in view

        ```

        ```
        $this->params['user']['id'] = 5;  //in controller
        $this->params['user']['name'] = "foo";
        $this->params['user']['email'] = "bar";

         // in view

        ```
- Models
    ------

    [](#models)

    - Write Data models in `models` directory.
    - `YourModel` must extend `Model`.
    - `YourModel` must implement methods:
        - tableName( ). Returns ( string ) name of table .
        - primaryKey( ). Returns ( string ) primary field name .
        - fields( ). Returns (array of string ) containing name of all fields except primary field. .
- Views
    -----

    [](#views)

    - Views can be rendered through controller by: ```
         return View::make('home', $this->params);

        ```
    - Write Views in `views` directory.
    - `Views` must declare document title by: ```
        //inside view

        ```
- Layouts
    -------

    [](#layouts)

    - You can have multiple layouts.
    - Write layouts in `views/layouts`
    - Set layout through respective controller by: ```
        $this->setLayout('layoutName');

        ```
- Sessions
    --------

    [](#sessions)

    - Sessions made easy.
    - Setting, Getting, Unsetting Session ```
        SESSION::set('key', 'value'); //setting session
        SESSION::get('key); //accessing set session
        SESSION::remove('key); //accessing set session

        ```
    - Setting and Getting Session Flash ```
        SESSION::setFlash('key', 'value'); //setting session flash
        SESSION::getFlash('key); //getting session flash msg

        ```
- Form Validation
    ---------------

    [](#form-validation)

    - Access predefined validations. ( Study `core/Validation.php` for all available validations. )
    - Example: ```
          $formFields = array(
                              "email"=>"foo@bar.com",
                               "password"=>"fooBar#123"
                             );

          $errors = Validation::validate($formFields)
          //returns array string of error messages.

          if ( empty($errors) ) {
             echo "All ok";
          } else {
              foreach ( $errors as $error ) {
                  echo $error.""
              }
          }

        ```
- Form and Field Components
    -------------------------

    [](#form-and-field-components)

    - Create forms using the Form and Field Component.
    - Syntax: ```
        Form::open('actionUrl', 'requestMethod');
        echo Form::field('inputType', [assoc array of attribute and values], 'optionalErrorMsg');
        echo "Login";
        Form::close();

        ```
    - Example: ```
          Form::open('', "post");
          echo Form::field("email", ['name' => 'email', 'placeholder'=>'Email here'], $errors['email'] ?? '');
          echo Form::field("password", ['name' => 'password', 'placeholder'=>'Password here'], $errors['password'] ?? '');
          echo "Login";
          Form::close();

        ```
- Basic CRUD Operation
    --------------------

    [](#basic-crud-operation)

    The `core/Model.php` contains commonly used CRUD operation.
    These operations are inherited by all `dataModels` in the `models` directory.
    Operations:

      Operation Method Params Description    Create record   save()   -   Inserts a record into table.     Read Single record by ID   fetch($id)   $id   Fetches record based on primary key.     Read Single record by XYZ   findOne($where)   $where   $where is a assoc array. Fetches record where multiple `WHERE` conditions are satisfied.     Update record   update($id)   $id   Updates single record based on id.     Delete record   delete($id)   $id   Deletes single record based on id.

FAQs
====

[](#faqs)

### 1. What does `$request->getMethod()` do?

[](#1-what-does-request-getmethod-do)

Returns `HTTP Request` method. Returns get, post, put, etc.

### 2. What does `$request->getBody()` do?

[](#2-what-does-request-getbody-do)

Returns assoc array of `HTTP Request` content. Mostly used to get `POST` data from form.

### 3. What does `$object->findOne($assocArray)` do?

[](#3-what-does-object-findoneassocarray-do)

Returns associative array from respective table where, fields and values match key and value of $assocArray.

### 4. What does `$object->initializeProperty($assocArray)` do?

[](#4-what-does-object-initializepropertyassocarray-do)

Returns void. Keys of the associative array are initialized as properties of object, values of associative array are set as respective property value.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

1318d ago

Major Versions

v0.3 → v1.1-BETA2022-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/45147f983db165bdafdd797027d6047f7a236058c1ffab91c047469a50b03ae6?d=identicon)[PG-Momik](/maintainers/PG-Momik)

---

Top Contributors

[![PG-Momik](https://avatars.githubusercontent.com/u/57512059?v=4)](https://github.com/PG-Momik "PG-Momik (9 commits)")[![Cooler-Momik](https://avatars.githubusercontent.com/u/114202124?v=4)](https://github.com/Cooler-Momik "Cooler-Momik (1 commits)")

### Embed Badge

![Health badge](/badges/momik-simple-mvc/health.svg)

```
[![Health](https://phpackages.com/badges/momik-simple-mvc/health.svg)](https://phpackages.com/packages/momik-simple-mvc)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[doppar/framework

The Doppar Framework

366.7k8](/packages/doppar-framework)[lion/bundle

Lion-framework configuration and initialization package

122.2k1](/packages/lion-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
