2014-02-22 53 views
0

我想創建一個文件目錄,但問題是我的索引頁面加載但它的空白頁面。以下是我所擁有的目錄類不工作php&xmapp

index.php 

<!DOCTYPE html> 
<html lang="en-GB"> 
<?php 
require_once ("../app/views/nav.php"); 
<body 
<p> test </p> 
</body 
</html> 
?> 

nav.php 
<div> 
<ul> 
<li> 
<a href="<?php fetchdir($views); ?>">TEST</a> 
</li> 
</ul> 

directories.class.php 
    class directories{ 
    function __construct(){ 
    //I am not using a database so I don't know what to put here 
    } 

    function fetchdir($dir) { 

     $host = $_SERVER['HTTP_HOST'].'/'; // The website host 
     $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http://' : 'https://'; //The HTTP(S) protocol 
     $branch = ""; // Dirs in URL from host to main folder 

     $protocol = $GLOBALS['protocol']; 
     $host = $GLOBALS['host']; 
     echo $protocol.$host.$branch.$dir; 
    } 

} 

$views = "views/"; 
$root = new directories; 

當我嘗試加載頁面時。我得到一個空白頁,但只要我remove

<a href="<?php fetchdir($views); ?>">TEST</a> 

頁面加載。

其他信息

httpd-vhosts.conf看起來像這樣

<VirtualHost *:80> 
    DocumentRoot "c:\Users\MYNAME\web-test\teDt202\web\html" 
    ServerName teDt202.local 
    <Directory c:\Users\MYNAME\web-test\teDt202\web> 
    # Apache 2.2 style access control (DEFAULT) 
    # Order allow,deny 
    # Allow from all 

    # Apache 2.4 style access contol (comment the next line if you're using below Apache 2.4) 
    Require all granted 

    AllowOverride all 
    </Directory> 
    AddHandler php5-script .htm 

    Alias /main c:\Users\MYNAME\web-test\teDt202\web\main 
    RewriteEngine on 
    RewriteCond %{LA-U:REQUEST_FILENAME} !-f 
    RewriteRule /(.*)$ /main/index.php/$1 [NS,PT,L] 

</VirtualHost> 

文件夾sturture

teDt202 <---main folder 
web 
app 
    classes <!-- all my class files are in here 
    views <!-- I have all my .php files are in here 
html <!-- I have my css, js and images files here 
main 
index.php 

請幫助。謝謝

回答

1

你有一個叫fetchdir()的函數,但它駐留在一個類中,因此如果不先實例化這個類,然後再調用函數作爲它自己的類的一個方法,就不能直接調用函數。

$directories = new directories; 

<a href="<?php $directories->fetchdir($views); ?>">TEST</a> 
+0

感謝您的重播我沒有實例化類,但兩件事情發生1)我的頁面加載沒有CSS和 – user3057514

+0

2)當我點擊導航我得到這樣的'HTTP鏈接上:// teDt202.local /%3Cbr%20 /%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20index:%20protocol%20in' blah blah blah – user3057514

+0

@ user3057514這是一個錯誤。你可以看到這是一個錯誤。未定義的索引協議。 – Ohgodwhy