Installation or testing process

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

Project Highlight

  • PSR-4
      "psr-4": {
          "App\\": "app/", 
        }
     
  • Simple Routing System
        $router->get('/', function($request) {
            $controller =  new HomeController($request) ;
           return $controller->home();
        });
    
    $router->get('/', 'HomeController@home'); 
    
    $router->get('/database-setup', 'DatabaseSetupController');
    
  • Dependency Injection Container
  •   namespace -  App\System\Base\Container;
      
      DependencyContainer::instance()->call("HomeController@index");
      DependencyContainer::instance()->call("HomeController", $parameters); // call __invoke method
      DependencyContainer::instance()->make(HomeController::class, $parameters); // get instance
      
      
  • Singleton Pattern
  • Dependency Inversion for Database Connection
  • MVC
  • Database Configuration setup from Form Input and create db.env file
            EnvManager::createEnvFile($configData); // create db.env file in /config dir
            EnvManager::get('host') // get config
      
  • Helper Function for redirect , json response, view
       responseJson("Something went wrong", 422);
       redirect('/home');
       sessionFlash('message', 'Successfully inserted');
       view('person.create', compact('types')
       view('person.create',["types" => $types])
       config('author.name') // get config data from /config/app.php
       url('home') // generate route url  
     
  • Data Compact from controller and extract from view and access from View File
       $purchase = new Purchase();
       $purchaseData = $purchase->getAll();
       return view('index', compact('purchaseData'));
       or
       return view('index', ['purchaseData' => $purchaseData]);
     
  • 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