GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - afgprogrammer/PHP-MVC-REST-API: A simple PHP MVC REST API framework with PHP 7.2 With routes and some tools to develop your API.

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
Application
Application
 
 
Router
Router
 
 
System
System
 
 
Upload/Images
Upload/Images
 
 
.htaccess
.htaccess
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
config.php
config.php
 
 
index.php
index.php
 
 

Repository files navigation

Guideline for using PHP MVC REST API

What is REST API?

A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.

An API is a set of definitions and protocols for building and integrating application software. It’s sometimes referred to as a contract between an information provider and an information user—establishing the content required from the consumer (the call) and the content required by the producer (the response). For example, the API design for a weather service could specify that the user supply a zip code and that the producer reply with a 2-part answer, the first being the high temperature, and the second being the low.

Introduction

Simply, the framework will route requests to the correct controller and model. It will do this by analysing request URI for the controller name and the request type (be it POST, PUT, GET, etc.). It will then do some sanity checks, before initialising a new controller and model object and calling the correct method on the controller.

Documentation

Add a new route

For creating a new route you should open Route.php file from Router directory.

There is already exist some examples in the file which you can use them as you need.

<?php

$router->get('/home', 'home@index');

$router->post('/home', 'home@post');

$router->get('/', function() {
    echo 'Welcome ';
});

For getting parameters follow below example:

<?php

$router->get('/:name', function($param) {
    echo 'Welcome ' . $param['name'];
});

For example, when I use this url "yourdomin.com/afgprogrammer" I will get following output.

Welcome afgprogrammer

It's just a Piece of cake :)

If you want to send the POST requests follow below example:

$router->post('/:name', function($param) {
    echo 'Welcome ' . $param['name'];
});

Database Connection

Consider that for using database you should edit config.php file before start using database.

For getting a database connection, you can use below sample in Model directory:

<?php

use MVC\Model;

class ModelsHome extends Model {

    public function getAllUser() {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user");
        
        /*
          $query->row : return 1 row
          $query->rows : return all rows
          $query->num_rows : return rows count
        */
        return $query->rows;
    }
}

About

A simple PHP MVC REST API framework with PHP 7.2 With routes and some tools to develop your API.

Topics

apiframeworkframework-mvcframework-phpmodel-view-controllermvcmvc-applicationmvc-architecturemvc-frameworkmvc-phpmvc-php-frameworkphpphp-frameworkphp-mvcphp72rest-apisimple-framework

Resources

Readme
MIT license
Activity

Stars

148 stars

Watchers

6 watching

Forks

41 forks
Report repository

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.