Reputation: 261
I am trying to create a file directory but problem is my index page loads but its a blank page. below is what I have
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;
When I try to load the page. I get a blank page but as soon as i remove
<a href="<?php fetchdir($views); ?>">TEST</a>
the page loads.
additional info
My httpd-vhosts.conf
looks like this
<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>
folder 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
please help. thanks
Upvotes: 0
Views: 82
Reputation: 50797
You have a function called fetchdir()
but it resides within a class, therefore you cannot call the function directly without first instantiating this class, and then calling the function as a method of the class its self.
$directories = new directories;
<a href="<?php $directories->fetchdir($views); ?>">TEST</a>
Upvotes: 1