2016-01-13 52 views
0

我得到了一些麻煩,我做了一個動態的,需要功能,我用它在兩個PHP文件,在同一目錄下,名爲database_controller.php和login.php中。事實是,當我在登錄文件中調用require函數時,它在一些測試中說我存在該文件但在此測試之後的要求沒有接受該文件。 而在我的文件database_controller當我調用需要的功能它的工作原理沒有問題所需的文件沒有工作,但所需的文件存在

的登錄文件測試的要求

require "./Utils/require.php"; 
if (file_exists(requires(intval($rows["role"])))) { 
    echo "exist"; 
    require requires(intval($rows["role"])); 
    echo "loaded"; 
    //doing something with the dynamic require 
} 
else { 
    echo requires(intval($rows["role"])); 
    exit; 
} 

當我跑我得到了錯誤500內部服務器錯誤和響應登錄的登錄文件僅僅是「存在」

這裏的./Utils/require.php

/** 
* @function requires 
* @param $userType 
* @return int|string 
*/ 
function requires($userType) { 
    switch($userType) { 
     case 0: 
      if (file_exists("Path to required file for user type 0")) { 
       return "Path to required file for user type 0"; 
      } 
     else 
      return 0; 
     case 1: 
      if (file_exists("Path to required file for user type 1")) { 
       return "Path to required file for user type 1"; 
      } 
      else 
       return 0; 
     case 2: 
      if (file_exists("Path to required file for user type 2")) { 
       return "Path to required file for user type 2"; 
      } 
      else 
       return 0; 
    } 
} 

個內容和這裏的什麼我具有相同功能的

require_once "./Utils/require.php"; 
require_once "./error.php"; 
/* 
* Post request method for packers 
*/ 
if ($UserType == 0) { 
    if (requires($UserType)) { 
     require requires($UserType); 
     //doing something with the dynamic required file 
    } 
} 
/* 
* Post request method for supervisors 
*/ 
elseif ($UserType == 1) { 
    if (requires($UserType)) { 
     require requires($UserType); 
     //doing something with the dynamic required file 
    } 
} 
/* 
* Post request method for admins 
*/ 
elseif ($UserType == 2) { 
    if (requires($UserType)) { 
     require requires($UserType); 
     //doing something with the dynamic required file 
    } 
} 

在這裏,我沒有在500內部服務器錯誤的database_controller做,我有200行,我有具體的形式顯示

+0

這裏之間的數據庫是請求頭: Host:easyweb.neyconsulting.ch User-Agent:Mozilla/5.0(X11; Linux x86_64; rv:38.0)Gecko/20100101 Firefox/38.0 Iceweasel/38.5.0 Accept:text/html,*/*; q = 0.01 Accept-Language:zh-cn,en; q = 0.5 Accept-Encoding:gzip,deflate DNT:1 Content-Type:application/x-www-form-urlencoded;字符集= UTF-8 X-請求-隨着:XMLHttpRequest的 的Referer:http://easyweb.neyconsulting.ch/ 的Content-Length:46 連接:保持活着 附註:無緩存 緩存控制:無-cache – FredS104

+0

和響應標頭: 連接:關閉 內容長度:5 內容類型:文本/ HTML;字符集= UTF-8 日期:星期三,2016年1月13日9點35分45秒GMT 服務器:Apache/2.4.10(Debian的) – FredS104

+0

有分號';'在一行缺少'回聲 「加載」'。另外我需要php的錯誤日誌。 – AnkiiG

回答

0

何不你只是使用自動加載? https://www.youtube.com/watch?v=VGSerlMoIrY

也許你只需要定義項目根的絕對路徑。 在分隔的文件將這個並要求它在你的公開的index.php

define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'] . '/your_project_root'); 

然後在公開的index.php只是

require_once'../app/the_config_file.php'; 

現在當你需要動態的東西只是不喜歡它:

require_once ROOT_PATH . '/path_to_the_file.php'; 
+0

我已經測試過,我也許發現問題在哪裏。如果我是對的,我會再發布它 – FredS104

+0

我解決了這個問題,它是兩個具有相同名稱的類之間的衝突。在login.php我使用DBLogin類的連接和所需的文件中調用DBLogin的第二個縮進,這是不同的類,因爲DBLogin – FredS104

+0

之間的數據庫訪問權不同0123h啊:D如果你想要有兩個具有相同名稱的類,可以使用名稱空間。這裏是例子:想象一下,你有一個名爲MP3的文件夾,裏面有1000首歌曲。名稱衝突的可能性很高。最好將這1000首歌曲組織成文件夾(按藝術家姓名)。這樣你可以擁有同名的歌曲,但是在不同的目錄下。命名空間就是這樣。您可以爲該類指定命名空間。而當你想在其他地方使用該類時,只需添加「use classname;」即可。檢查一下,這是有幫助的 – JosefPP

0

我解決了它是兩個具有相同名稱的類之間的衝突的問題。在我的login.php使用DBLogin類的連接,並在呼叫DBLogin的第二凹部所需的文件,該文件是不一樣的,因爲類的不同的訪問權,以既DBLogin