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) <?php

class 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
@Bramz

2 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

Tanggapan

Tolong rapihkan code nya

2 Jawaban:

Jawaban Terpilih

<div>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.<br>Di coba saja,&nbsp;<br><br></div><pre>&lt;?phpclass App{ protected $controller = 'Home', $method = 'index', $params = []; public function __construct() { $url = $this-&gt;parseurl(); //controller if ($url == NULL) { $url = [$this-&gt;controller]; } if (file_exists('../app/controllers/' . $url[0] . '.php')) { $this-&gt;controller = $url[1]; // unset($url[1]); var_dump($url); } require_once '..app/controllers/' . $this-&gt;controller . '.php'; $this-&gt;controller = new $this-&gt;controller;</pre>

avatar VikSintus
@VikSintus

96 Kontribusi 36 Poin

Dipost 4 tahun yang lalu

<div>Di windows dan linux struktur directory nya berbeda, gunakan DIRECTORY_SEPARATOR, Dan DIR</div>

avatar marilynbathory
@marilynbathory

61 Kontribusi 9 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban