Belajar MVC PHP,

mengikuti tutor mvc, saat programny unset($url[0]); dan unset($url[1]); lalu di var_dump yang seharusnya home dan about hilang. saat di jalankan home dan about jalan saya menggunakan PHP 7.4.3-4ubuntu2.19.. apakah dikarenakan versi phpny terlalu rendah ya pak? Mohon Saran Masukkan Pak ?

koding di core/App.php

<?php

class App{
    protected $controller = 'Home';
    protected $method = 'index';
    protected $params = [];

    public function __construct()
    {
        $url = $this->parseURL();
       

        //controller
        if(file_exists("../app/controllers" . $url[0] . '.php')) {
            $this->controller = $url[0];
            unset($url[0]);
        }
        require_once "../app/controllers/" . $this->controller . ".php";
        $this->controller = new $this->controller;


        //method

        if(isset($url[1])) {
            if(method_exists($this->controller, $url[1])){
                $this->method = $url[1];
                unset($url[1]);
            }
        }
    //params
        if(!empty($url)){
            var_dump($url);
        }

    }

    public function parseURL()
   {
         if(isset($_GET['url'])){
            $url = rtrim($_GET['url'], '/');
            $url = filter_var($url, FILTER_SANITIZE_URL);
            $url = explode('/', $url);
            return $url;
        }
     
    }
}

koding controllers/About.php dan Home.php

<?php   

class About{
    public function page()
    {
        echo "About/page";
    }
}
<?php

class Home {
    public function index(){
        echo "home/index";
    }
}
avatar argachristian
@argachristian

11 Kontribusi 1 Poin

Dipost 3 bulan yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban