1

这是我的“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':

'博客.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”时,我收到以下错误:

致命错误:第 8 行的 C:\wamp\www\kapantzakis_2.14\pages\blog_list.php 中找不到类“数据库”

我认为当 ajax 调用这个文件时,php 不会在 'blg_list.php' 中执行 require_once。

不知道我解释的好不好。

谢谢你的帮助!

编辑#1

阿贾克斯调用:

// 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);
        }
4

2 回答 2

2

我假设您的文件夹结构如下所示:

kapantzakis_2.14/
  articleLoader.php
  blog.php
  blog_list.php
  index.php
  pages/
    home.php
  phpScripts/
    Database.php

您的 AJAX-Callpages/blog_list.php直接请求,但在您的问题文本中,它似乎blog_list.php位于您的根目录 ( kapantzakis_2.14) 中。

您得到的错误 ([...] 'Database' not found in C:\wamp\www\kapantzakis_2.14\pages\blog_list.php[...]) 显示blog_list.php位于pages-folder 中。您的 -callglob找不到phpScriptspages-Folder 中调用的目录,因此required_once调用永远不会被执行。

于 2012-11-03T20:03:12.870 回答
0
// add this line on the top of your script
ob_start();


// add this line on the bottom of your script
$errors = ob_get_contents();
ob_end_clean();
$fopen = fopen('errors.txt', 'w+');
fwrite($fopen, $errors);
fclose($fopen);

你可以得到所有的错误

于 2012-11-03T20:02:00.240 回答