これは私の「index.php」ファイルです(その一部):
<?php
// Require every .php file inside "phpClasses" folder
foreach (glob("phpScripts/*.php") as $filename) {
require_once $filename;
}
// Create the $db object
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// Connect to the database
$db->connect();
// Instantiate the "language" and "databaseQuery" classes
$lang = new language();
$dbQuery = new databaseQuery();
// Detect if the laguage has changed from the user and apply the new "current language"
if(isset($_GET["change_lang"])) {
$change_lang = $_GET["change_lang"];
$cur_lang = $change_lang;
} else {
$cur_lang = $lang->getCurLang();
}
?>
<head>
...
</head>
<body>
<div id="cur_content" class="temp_content" data-tempPos="0">
<?php
include 'pages/home.php';
?>
</div> <!-- #cur_content -->
</body>
#cur_content 内に、ajax 呼び出しを介して「blog.php」を挿入します。
「blog.php」:
<div id="blog_main_content" class="temp_content">
<?php
include "blog_list.php";
?>
</div>
..そしてその中に、「blog_list.php」を含めます:
foreach (glob("phpScripts/*.php") as $filename) {
require_once $filename;
}
// Create the $db object
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// Connect to the database
$db->connect();
$dbQuery = new databaseQuery();
// Get the language from loader.php
$cur_lang = "'".$_SESSION['language']."'";
$dbQuery->getArticleList($cur_lang);
?>
#blog_main_content div 内で、ajax 呼び出しを介して「articleLoader.php」を挿入し、正常に動作します。初めて「blog_list.php」が正常に表示されました。ユーザーが ajax 呼び出しを介して「blog_list.php」に戻ると、次のエラーが発生します。
致命的なエラー: クラス 'Database' が C:\wamp\www\kapantzakis_2.14\pages\blog_list.php の 8 行目に見つかりません
ajax がこのファイルを呼び出した場合、php は 'blg_list.php' 内の require_once を実行しないと思います。
うまく説明できているかわかりません。
助けてくれてありがとう!
編集#1
Ajax 呼び出し:
// Perform the ajax call
function getAjaxPage(method, content, currentOffset) {
var temp_content = $('.temp_content');
var temp_content_last = temp_content.filter(':last');
var blog_main_content = $('#blog_main_content');
var blog_main_content_first = blog_main_content.filter(':first');
// Insert the html data in to the first or last div depending on the movement of the page
if (method == 'next') {
var insert_div = temp_content_last;
} else if (method == 'prev') {
var insert_div = blog_main_content_first;
}
// Get article or the article list
if (content == 'article') {
var page = 'articleLoader.php';
} else if (content == 'article_list') {
var page = 'pages/blog_list.php';
}
/*
var lang = getCurLang();
var data = 'lang=' + lang + '&art_id=' + art_id;*/
var tags_wrapper = $('#tags_wrapper');
$.ajax({
url: page,
type: "GET",
/*data: data,*/
cache: false,
success: function (html) {
insert_div.html(html)
.queue(function() {
var return_to_list = $('#return_to_list');
return_to_list.attr('data-offsetTop', currentOffset);
returnTopOffset();
if (content == 'article') {
tags_wrapper.fadeIn(800);
} else if (content == 'article_list') {
tags_wrapper.hide();
}
$(this).dequeue();
});
}
});
return $(this);
}