Postingan lainnya
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
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, <br><br></div><pre><?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;</pre>
<div>Di windows dan linux struktur directory nya berbeda, gunakan DIRECTORY_SEPARATOR, Dan DIR</div>