Hier wird die Struktur meiner Anwendung ist:Fügen Sie eine Datei aus dem Stamm
core
application
controller_base.class.php
registry.class.php
router.class.php
template.class.php
controller
include
config.php
model
views
index.php
Die Datei config.php in der index.php Datei enthalten ist (es gibt kein Problem mit diesem) und hier ist, was es enthält :
<?php
/*** include the controller class ***/
include(ROOT . '/core/application/controller_base.class.php');
/*** include the registry class ***/
include(ROOT . '/core/application/registry.class.php');
/*** include the router class ***/
include(ROOT . '/core/application/router.class.php');
/*** include the template class ***/
include(ROOT . '/core/application/template.class.php');
/*** autoload model classes ***/
function __autoload($class_name) {
$filename = strtolower($class_name) . '.class.php';
$file = ROOT . '/core/model/' . $filename;
if (!file_exists($file)) {
return false;
}
// include the $class_name class
include($file);
}
$registry = new registry;
Sie müssen wissen, dass die konstante ROOT wie folgt definiert ist:
define('ROOT', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
diese konst ant enthält den Wert /Lab/Livre/POO/TP1
, der natürlich die Wurzel der Anwendungen ist.
Aber es gibt ein Problem mit allen Dateien, die ich in der config.php einschließe. PHP wirft mir einen Fehler, der besagt, dass die Dateien in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php
nicht gefunden werden.
So ist das Problem klar. Ich möchte PHP nach den Dateien aus dem Stamm der Anwendung (wo index.php ist) suchen, aber es sucht aus dem Ordner, in dem config.php befindet.
Ich hatte dieses Problem für eine lange Zeit, aber ich möchte eine Lösung für immer finden.
Ich kann es nicht tun, will ich will! Ich hoffe, dass mir jemand hilft.
Vielen Dank.
S.S .: Mit anderen Worten, ich möchte die Dateien mit einem absoluten Pfad einschließen.
P. S .: Hier ist der vollständige Fehlertext:
Warning: include(/Lab/Livre/POO/TP1/core/application/controller_base.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 4
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/controller_base.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 4
Warning: include(/Lab/Livre/POO/TP1/core/application/registry.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 7
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/registry.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 7
Warning: include(/Lab/Livre/POO/TP1/core/application/router.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 10
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/router.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 10
Warning: include(/Lab/Livre/POO/TP1/core/application/template.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 13
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/template.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 13
Können Sie uns den vollständigen Fehlertext kopieren? – olibiaz
Fertig! Tut mir leid, ich habe es vergessen. – tomfl
So php versucht nicht, die erforderliche Datei im selben Ordner wie config.php zu laden. Es findet die Dateien nicht in '/ Lab/Livre/POO/TP1/core/application /'. – olibiaz