我正在尝试创建一个文件目录,但问题是我的索引页面加载但它是一个空白页面。以下是我所拥有的
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
请帮忙。感谢
答案 0 :(得分:1)
你有一个名为fetchdir()
的函数但是它驻留在一个类中,因此你不能在没有首先实例化这个类的情况下直接调用该函数,然后将该函数作为一个类的方法调用它自己。
$directories = new directories;
<a href="<?php $directories->fetchdir($views); ?>">TEST</a>