မိမိကိုယ်ပိုင် MVC Framework တွင် Router အသုံးပြုခြင်း

index.php ဖိုင်ရှိ လက်ရှိအကြောင်းအရာကို ပြန်လည်သုံးသပ်ကြည့်ပါ။

index.php<?php
  namespace Core;
  
  error_reporting(E_ALL);
  ini_set('display_errors', 'on');
  
  spl_autoload_register(function($class) {
    // သင့်ရဲ့ autoload အကောင်အထည်ဖော်မှု
  });
  
  $routes = require $_SERVER['DOCUMENT_ROOT'] . '/project/config/routes.php';
?>

ယခု index.php ထဲတွင် ကျွန်ုပ်တို့၏ Router ကို အောက်ပါအတိုင်း အသုံးပြုလိုသည်ဆိုကြပါစို့။

index.php<?php
  $router = new Router();
  $track  = $router->getTrack($routes, $_SERVER['REQUEST_URI']);
?>

ပိုမိုကျစ်လျစ်စွာ ပြန်ရေးနိုင်ပါသည်။

index.php<?php
  $track = ( new Router ) -> getTrack($routes, $_SERVER['REQUEST_URI']);
?>