Warning: require_once(..app/controllers/Home.php): failed to open stream

muncul pesan error :
Warning: require_once(..app/controllers/Home.php): failed to open stream: No such file or directory in C:\xampp\htdocs\phpmvc\app\core\App.php on line 22

Fatal error: require_once(): Failed opening required '..app/controllers/Home.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\phpmvc\app\core\App.php on line 22

Struktur Folder :
folder phpmvc :
1. Controllers
    - About.php
    - Home.php
2. Core
    - App.php
    - controller.php
 


Script :
(letak : phpmvc/core/App.php)

<?phpclass App{    protected        $controller = 'Home',        $method = 'index',        $params = [];
    public function __construct()    {        $url = $this->parseurl();
        //controller        if ($url == NULL) {            $url = [$this->controller];        }        if (file_exists('../app/controllers/' . $url[0] . '.php')) {            $this->controller = $url[0];            // unset($url[0]);            var_dump($url);        }
        require_once '..app/controllers/' . $this->controller . '.php';        $this->controller = new $this->controller;


//mohon problem solvingnya lur


avatar Bramz

Ditanyakan oleh @Bramz

1 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

mungkin posisi Home.php bukan berada di $url[0] tapi berada di $url[1] coba di ganti atau coba lihat posisi index Home.php apakah di [0] atau di [1] atau dengan kata lain apakah Home.php di urutan pertama atau di urutan ke dua.
Di coba saja, 

<?phpclass App{    protected        $controller = 'Home',        $method = 'index',        $params = [];
    public function __construct()    {        $url = $this->parseurl();
        //controller        if ($url == NULL) {            $url = [$this->controller];        }        if (file_exists('../app/controllers/' . $url[0] . '.php')) {            $this->controller = $url[1];            // unset($url[1]);            var_dump($url);        }
        require_once '..app/controllers/' . $this->controller . '.php';        $this->controller = new $this->controller;
avatar VikSintus

Dijawab oleh @VikSintus

92 Kontribusi 31 Poin

Login untuk menanggapi


Di windows dan linux struktur directory nya berbeda, gunakan DIRECTORY_SEPARATOR, Dan __DIR__
avatar Cvar1984

Dijawab oleh @Cvar1984

58 Kontribusi 8 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi