Git Product home page Git Product logo

php-mvc's Introduction

Installation or testing process

  • Pull project to your server with git or download
      git clone https://github.com/emrancu/php-mvc.git
      
  • Create a Database
  • Open Project and submit your database name, user & password
  • Then Done

Project Highlight

  • PSR-4
      "psr-4": {
          "App\\": "app/",
          "Route\\": "route/"
        }
     
  • Routing System

    $router->get('/', function($request) { $controller = new HomeController($request) ; return $controller->home(); });

    $router->post('/saveData', function($request) { $controller = new PurchaseController($request) ; return $controller->saveData(); });

  • MVC
  • Database Configaration setup from Form Input and create db.env file
       $configData = 'database=' . $this->request->get('database_name') . PHP_EOL;
            $configData .= 'user_name=' . $this->request->get('user_name') . PHP_EOL;
            $configData .= 'password=' . $this->request->get('password') . PHP_EOL;
    
        // generate env file
        DynamicDBConfig::createEnvFile($configData);
    
  • Helper Function for redirect , json response, view

    // return as json function json($data = [], $code = 200) { header_remove(); http_response_code($code); header("Cache-Control: no-transform,public,max-age=300,s-maxage=900"); header('Content-Type: application/json'); $status = array( 200 => '200 OK', 400 => '400 Bad Request', 422 => 'Unprocessable Entity', 419 => 'Unauthenticated Entity', 500 => '500 Internal Server Error' ); header('Status: ' . $status[$code]); echo json_encode($data); return; }

    // redirect expected route function redirect($route = '') { $dir = dirname($_SERVER['PHP_SELF']); header("Location: " . $dir . $route); }

  • Data Compact from controller and extract from view and access from View File

    $purchase = new Purchase(); $purchaseData = $purchase->getAll(); return view('index', compact('purchaseData'));

    function view($fileName, $data = []) { if (count($data)) { extract($data); } require_once DIR . '/../../view/' . $fileName . '.php'; unsetFlashSession(); }

  • Flush Session for one-time (reset after page loaded)
    // unset flush session
    function unsetFlashSession()
    {
        foreach ($_SESSION as $key => $value) {
            if (strpos($key, 'app_flash_') === 0) {
                unset ($_SESSION[$key]);
            }
        }
    }
    

    // set or get session function sessionFlash($name, $message = '') { if ($message) { $SESSION["app_flash" . $name] = $message; } else { return $SESSION["app_flash" . $name] ?? ''; } }

  • Data Validation System with PHP
           $check = Validator::execute($this->request, [
                'amount' => 'required|number',
                'buyer' => 'required|noSpecialChar|limit:20,50',
                'receipt_id' => 'required|letter',
                'buyer_email' => 'required|email',
                'note' => 'required|wordLimit:2,30',
                'city' => 'required|letter',
                'phone' => 'required|mobile',
                'entry_by' => 'required|number'
            ]);
    
           if (!$check['status']) {
               return json($check, 419);
           }
     
        
    
  • Input Field Data Validation System with JS:

    Self Developed: Field Validator

  • WebToast/ alert system:

    Self Developed: webToast

  • JS Fetch for Ajax Request
# License

The MIT License (MIT)

Developed with โค by AL EMRAN

php-mvc's People

Contributors

emrancu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.